Ah - I think I understand now.

I would add a column to the comments table called 'kind' (as in, 'kind
of comment')

The column should be an integer column with limit 1.

Then assign a different integer value to determine what kind of
comment it is.

i.e.,
1 = article
2 = photo
3 = movie

When you creating a new comment, simply check the value of this
integer and redirect accordingly.

Does that help?

On Feb 22, 3:27 pm, Difei Zhao <[email protected]>
wrote:
> Gavin wrote:
> > 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?
>
> Hi Garvin, but your way is to decide the father of an existed comment.
> if I just received POST to /articles/:article_id/comments/:comment_id,
> and I have a:
> @comment = Comment.new(params[:comment]), how could I tell this @comment
> is for article but not photo? By test params?
>
> Thanks.
>
>
>
> > On Feb 21, 5:53 am, Difei Zhao <[email protected]>
>
> --
> 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