2012-12-02 63 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

相關問題