2012-12-02 145 views
1

我一直在尝试为我的RoR 3网站创建一个类似的按钮。我已使用此链接中建议的解决方案:Simple like/unlike button with rails 3, jquery, and ajax无法批量分配受保护的属性:post_id

我有一个用户,发布和类似的模型。但是类似的按钮部分在我的显示帖子页面显示“Can not mass assign protected attributes: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 

在此先感谢。

回答

1

添加attr_accessible:POST_ID,:USER_ID您喜欢的模型

+0

谢谢..它的工作... – user1870562

+1

高兴地听到!你能帮我一个忙,并选择我的答案作为最终答案吗? – bjoern

相关问题