activerecord - Rails 3: Restrict a many-to-many relationship -


I have several-to-many relationships: user - & lt; Comments & gt; - Products however, I only want to see a product comment for my author.

This is the route:

  Resources: do product resources: comments ending   

The controller will do something like this:

  # @product loaded before_filter@comments = @ product.comments.where (: author_id = & gt; current_user) # back 0 or 1 record   

I can change these routes:

  Resources: Product Processing: Comments Ended   

Then Show Action Use:

  # @product ago_Filter loaded in @comment = @ product.comments.where (: author_id = & gt; current_user) # back 0 or 1 record   

If there is no comment, then it may be necessary to take a new action Vchalit be root, but I was not able to make it work.

Is this a proper approach to this user-case?

You can create redirect_to in your show-method, no comments.

Comments