Re: Hatred towards Nested Polymorphic Paths

Tim Lucas
2007-08-04T01:08:18Z

On 04/08/2007, at 8:39 AM, Brian Hogan wrote:

> Indeed. I''d love to see examples of this proxy for authentication
> for teams of which he speaks. :)

/projects/3/tasks/8/notes/2

class User < ActiveRecord::Base
   has_many :roles
   has_many :projects, :through => :roles
end

class Project < ActiveRecord::Base
   has_many :tasks
end

class Task < ActiveRecord::Base
   has_many :notes
end

class NotesController < ApplicationController
   before_filter :find_project
   before_filter :find_task
   before_filter :find_note

   def show
   end

   protected
     def find_project
       @project = current_user.projects.find(params[:project_id])
     end
     def find_task
       @task = @project.tasks.find(params[:task_id])
     end
     def find_note
       @note = @task.notes.find(params[:id])
     end
end

Notice each find is scoped using it''s AR associations proxy, starting
from current_user.projects

-- tim