Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3.2 Can';t mass assign protected attributes:post_id_Ruby On Rails 3.2 - Fatal编程技术网

Ruby on rails 3.2 Can';t mass assign protected attributes:post_id

Ruby on rails 3.2 Can';t mass assign protected attributes:post_id,ruby-on-rails-3.2,Ruby On Rails 3.2,我一直在尝试为我的ROR3网站创建一个类似的按钮。我使用了此链接中建议的解决方案: 我有一个用户,帖子和喜欢的模型。但是like按钮部分显示了我的show posts页面中的“不能批量分配受保护的属性:post_id”错误。我已经研究了其他线程的解决方案,但似乎没有任何工作。粘贴我的代码摘要以供参考 class Like < ActiveRecord::Base belongs_to :user belongs_to :post end class Post < Activ

我一直在尝试为我的ROR3网站创建一个类似的按钮。我使用了此链接中建议的解决方案:

我有一个用户,帖子和喜欢的模型。但是like按钮部分显示了我的show posts页面中的“不能批量分配受保护的属性:post_id”错误。我已经研究了其他线程的解决方案,但似乎没有任何工作。粘贴我的代码摘要以供参考

class Like < ActiveRecord::Base
  belongs_to :user
  belongs_to :post
end

class Post < ActiveRecord::Base
   attr_accessible :title, :content, :posts_attributes
   belongs_to :user
   has_many :likes
   accepts_nested_attributes_for :likes
   .
   .
   .
end

class User < ActiveRecord::Base
   attr_accessible :email, :name, :password, :password_confirmation
   has_many :posts, dependent: :destroy
   has_many :likes
   .
   .
   .
end
类类似于

提前感谢。

将attr\u accessible:post\u id,:user\u id添加到您的同类车型中

将attr\u accessible:post\u id,:user\u id添加到您的同类车型中

很高兴听到这个消息!你能帮我一个忙,选择我的答案作为最终答案吗?很高兴听到!你能帮我一个忙,选择我的答案作为最终答案吗?