ruby-on-rails – 在模型创建期间Rails未知属性
发布时间:2020-12-17 02:44:19 所属栏目:百科 来源:网络整理
导读:我有一条错误消息 – “unknown attribute:news_id”但我无法理解问题所在.我有新闻控制器,我想为每条新闻创建评论.我希望有人可以帮助我.提前致谢. schema.rb create_table "comments",:primary_key = "ID",:force = true do |t| t.integer "Author_ID" t.
我有一条错误消息 – “unknown attribute:news_id”但我无法理解问题所在.我有新闻控制器,我想为每条新闻创建评论.我希望有人可以帮助我.提前致谢.
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 评论模型: belongs_to :news 新闻模式: has_many :comments 解决方法
这是因为您没有在评论模型中添加:news_id.
编写迁移以将news_id添加到Comment中,您的问题将得到解决. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |