Re: Hatred towards Nested Polymorphic Paths

Paolo Negri
2007-08-03T22:23:26Z

I think nested routes are quite cool and useful, specially if instead
of using numerical IDS you use codes that have a meaning for the user

so

projects/2/tasks_category/3/task/5

becomes

projects/CoolWebApp/task_categories/design/tasks/user_profile

Such a url is hackable and meaningful, it''s currently supported by
rails and I''d be disappointed if it won''t anymore.

that''s my 0.02

Paolo

On 03/08/07, Michael Glaesemann <grzm@seespotcode.net>
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
>
>
>
> >