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.