Unknown Rails attribute during model creation

I have an error message - "unknown attribute: news_id", but I can not understand where the problem is. I have a news controller and I want to create comments for each news. I hope someone can help me. Thanks in advance.

schema.rb

create_table "comments", :primary_key => "ID", :force => true do |t| t.integer "Author_ID" t.integer "News_ID", :null => false t.string "Content", :limit => 500, :null => false t.datetime "Date", :null => false end 

Comment Model:

 belongs_to :news 

News Model:

 has_many :comments 
+4
source share
2 answers

This is because you did not add :news_id to your Comment model.

Write a post to add news_id to the comment and your problem will be resolved.

+7
source

You can print out puts params parameters when you run your create action to check the actual attributes that it sends.

or you can check the routes that you have to create comments to get the parameter.

0
source

Source: https://habr.com/ru/post/1435564/


All Articles