Re: Hatred towards Nested Polymorphic Paths

court3nay
2007-08-04T02:59:55Z

Those filters are easily memcached when you start hitting loads, and
are easily stubbed in your controller spec.  You can also combine some
of those calls with an :include.

Also, some of the actual find_xx methods belong in application
controller.

-------
Courtenay

On Aug 3, 2007, at 6:30 PM, "Brian Hogan" <bphogan@gmail.com>
wrote:

> ha! Of course. That makes total sense. :) Wow. Sometimes it''s
right
> there in front of you. Thanks a lot!
>
> On 8/3/07, Tim Lucas < t.lucas@toolmantim.com> wrote:
>
> 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
>
>
>
>
>
>
> >