Difei,

If a comment only belongs to either an article, movie or a photo
(never more than one) you could add methods in the model to determine
which it is for.

For example:

class Comment

  def article_comment?
    !article_id.nil?
  end
end

@comment.article_comment? will return true if this is a comment for an
article and false if not.

You could render your view accordingly for each type of comment.

Hope that helps?

On Feb 21, 5:53 am, Difei Zhao <[email protected]>
wrote:
> Hi all,
>
>   I have several resources:
>
>   map.resources :articles, :has_many => [:comments]
>   map.resources :movies, :has_many => [:comments]
>   map.resources :photos, :has_many => [:comments]
>
>   all of them have a nested resource named comments, new comments are
> able to be created by POST to URLs like article_comments_url. My problem
> is, when I'm in the comments_controller, how can I know which resource
> this comment belongs to? By reading the params? I think this is not
> decent, are there any better ways? Thanks in advance!
>
> Cheers,
> Difei
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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