views:

47

answers:

1

Hey guys,

lets say I have the comments model, nested under the posts model.

Now lets say I add a user model, and I want the user to be able to see their comments, in their profile. So I nest the comments model under the posts model as well?

So far - this hasnt been working

A: 

Like so:

map.resources :users do |user|
  user.resources :comments
end

map.resources :posts do |user|
  user.resources :comments
end

This should work fine. There are a couple caveats:

  1. Sometimes the CommentsController will get params[:user_id], and sometimes it will get params[:post_id], depending on the URL. In the comments#index action, for example, you must look up a different set of comments depending on the context.

  2. You'll have two different URLs for the same comment. This may or may not be a problem for your site.

ndp