1

I have been trying to create a like button for my RoR 3 site. I have used the solution suggested in this link: Simple like/unlike button with rails 3, jquery, and ajax

I have a user, post and like model. But the like button partial shows a "Can't mass assign protected attributes :post_id" error from my show posts page. I have researched other threads for solutions but nothing seems to work. Pasting excerpts of my code for reference.

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

Thanks in advance.

Community
  • 1
  • 1

1 Answers1

1

add attr_accessible :post_id, :user_id to your Like model

bjoern
  • 1,009
  • 3
  • 15
  • 31