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 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.

The user table contains all the fields that are generated by the device by default. The paragraph table contains fields such as 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 .

Expected Organization:

  class comment & lt; ActiveRecord :: Base is_to: article is_to: user   

I want to make sure that only logged in users can comment on the article, and that is is_admin User can create new article.

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

  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   

Second: article

  class article has_many: comments, dependent => : Destroy is_to: user end   

third: comment

  class comment belongs_to: for user: end of article    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -