【发布时间】:2012-12-02 15:56:25
【问题描述】:
我一直在尝试为我的 RoR 3 网站创建一个赞按钮。我已使用此链接中建议的解决方案:Simple like/unlike button with rails 3, jquery, and ajax
我有一个用户、帖子和点赞模型。但是喜欢按钮部分显示我的显示帖子页面中的“无法批量分配受保护的属性: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
提前致谢。
【问题讨论】: