On Sep 6, 4:35 am, Ed <[email protected]> wrote:
> Trying to convert my app (and brain) to RESTful routes from the old
> style.  What is the accepted approach to nesting a resource within 2
> other resources?
>
> Example:
>
> Models
>
>   Person has_many :scores
>   Contest has_many :scores
>   Score belongs_to :person, :contest
>
> Routes
>
>   resources :people do
>     resources :scores
>   end
>
>   resources :competitions do
>     resources :scores
>   end
>


I think that you should use HABTM :through, the rest should be easy

> I want to be able to list scores by person, or by competition.  Either
> of the these two paths will request the :index action in the :scores
> controller:
>
> GET /people/person_id/scores
> GET /contests/contest_id/scores
>
> So what is the best way to structure scores/index to deliver the
> appropriate list?
>
> I could test for the presence of params[person_id] or
> params[contest_id], then execute and render accordingly within
> the :index action.  But that seems somewhat inelegant.  Is there a
> better way?  Should I have two separate actions within the :score
> controller, and modify my route mapping somehow to request the
> appropriate action?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" 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-talk?hl=en.

Reply via email to