Associations in ruby on rails -
I have created a user using device authentication. I have created article view, controller and model, where in the model The user table contains all the fields that are generated by the device by default. The paragraph table contains fields such as Expected Organization: I want to make sure that only logged in users can comment on the article, and that is How can I create relationships between users, articles and comment tables? Do I need to organize for user and comment table? It is advisable to go through the rail guide and to the association as a small blog @depage Understand the suggestion in the comment. Looks like you already have work, then integrate me. As you have said, you will have three models: First: user Second: article third: comment title ,
body and
article_id are now I want to apply comments (with the condition that the user logged in on only one article Can do). I have created a
is_admin as a special user who created new articles through the application through power.
article_id ,
title , and
body between the user and the article table. In the comment table (according to my understanding) will be
comment_id and
comment_body .
class comment & lt; ActiveRecord :: Base is_to: article is_to: user
is_admin User can create new article.
near the class user: text # not depend = Gt; : Delete, do you want to delete the article on the user's delete: comment, dependent => : Delete end
class article has_many: comments, dependent => : Destroy is_to: user end
class comment belongs_to: for user: end of article
Comments
Post a Comment