I've got three (relevant) models, specified like this:
class User < ActiveRecord::Base
has_many :posts
has_many :comments
has_many :comments_received, :through => :posts, :source => :comments
end
class Post < ActiveRecord::Base
belongs_to :user
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :user
belongs_to :post
end
I'd like to be able to reference all the comments_received
for a user
with a route - let's say it's for batch approval of comments on all posts. (note that you can also get comments
made by the user
, but users can't comment on their own posts, so the comments
through a post
are different and mutually exclusive). Logically, this should work with:
map.resources :users, :has_many => [:posts, :comments, :comments_received]
This should give me routes of
user_posts_path
user_comments_path
user_comments_received_path
The first two work, the last one doesn't. I've tried it without the _
in comments_received
to no avail. I'm looking to get a URL like
http://some_domain.com/users/123/comments_received
I've also tried nesting it, but maybe I'm doing that wrong. In that case, I'd think the map would be:
map.resources :users do |user|
user.resources :comments
user.resources :posts, :has_many => :comments
end
and then the url might be:
http://some_domain.com/users/123/posts/comments
Maybe this is the right way to do it, but I have the syntax wrong?
Am I thinking about this the wrong way? It seems reasonable to me that I should be able to get a page of all the comments
added to all of a user's posts.
Thanks for your help!