Rails Nesting paths, not resources -
i have author
model name
field - has_many
articles.
i have article
model name
, description
fields - belongs_to
author , has_many
comments.
finally, have comment
model, comment_text
, article_id
fields - belongs_to
article,
i looking nesting paths i. e. ,(authors/:id/comments) how nest paths, not resources?
to clarify, don't want use author_id
in comment model, when visit authors/:id/comments, should able see articles associated author , comment on them.
author
has_many :articles has_many :comments, :through => :articles (this line give comments author)
article
belongs_to :author (means has author_id field) has_many :comments
comment
belongs_to :article
if above structure there in model, can do:
@author = author.where(:id => some_id) @comments = @author.comments
you don't need have author_id in comment table.
Comments
Post a Comment