Sure. Very much so... and that's exactly how I've been doing it. So what I understand is that it's perfectly fine to query the database that many times, because it's good for security and data integrity. I can live with that. Just wanted to make sure that was the best way to explain it to my students. Some people will surely look at the sql logs and see four separate (albeit small) queries and wonder why that's necessary, so I want to have a good answer for them.
Thanks everyone! I really appreciate it. On 8/3/07, Michael Glaesemann <[EMAIL PROTECTED]> wrote: > > > > On Aug 3, 2007, at 17:01 , Brian Hogan wrote: > > > Well see that's exactly why I am confused. > > I understand the data integrity thing and the security thing, but > > how far do you take that? > > > > /users/1/projects/2/tasks/3/notes/4 > > > > @user.find(params[:user_id] > > @project @user.projects.find(params[:project_id] > > @task = @project.tasks.find(params[:task_id] > > @note = @task.notes.find(params[:id] > > > > That just really seems to get messy. Is that really the approach > > you'd take? I assume you'd use some sort of includes there to > > reduce the db calls then, right? > > > > AIUI, In this situation, I'd be in the notes_controller. I'd have > already set up find_user, find_project, find_task, and > find_note_by_id methods called by before_filter, e.g., > > # in application.rb > private > def find_user > @user = User.find(params[:user_id]) > end > > def find_project > @project = @user.projects.find(params[:project_id]) > end > > def find_task > @task = @project.tasks.find(params[:task_id]) > end > > # in notes_controller.rb > private > before_filter :find_user > before_filter :find_project > before_filter :find_task > before_filter :find_note, :except => [:index, :new, :create] > > def find_note_by_id > @note = @task.notes.find(params[:id]) > end > > Very succinct, I believe. > > Michael Glaesemann > grzm seespotcode net > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
