0

I am trying to create and implement a like/unlike button to a post model in rails. The only thing I sort of understand is I need some sort of relationship model with a has_many_through association. can any one point me in the right direction to create this. I will prefer to create it from scratch to full understand it. thanks

Ganesh Kunwar
  • 2,643
  • 2
  • 20
  • 36
  • you need to tell us what you've already done. we can help in any difficulty you've encountered but you need to let us know that you've really done something first :) – jvnill Mar 06 '13 at 06:00
  • @joshua, check this out http://stackoverflow.com/questions/3703194/like-dislike-plugin-for-rails – sameera207 Mar 06 '13 at 06:47
  • @sameera207 thanks alot!!!! didn't even think about taking that route to implement it. just what i needed. –  Mar 06 '13 at 11:08

2 Answers2

1

Well, it seems like you have a Person model. And you have a Post model. That Person model can be related to a Post model through something like an Opinion model (ugh... I hate trying to name relational models -- but the only thing I despise more would be a PersonPost model -- its not a PersonPost -- the person making the vote up or down isn't the poster - but enough of that). Opinion has a person_id and a post_id (and whatever other fields you think are useful).

So Person has_many :opinions has_many :posts, :through => :opinions

Opinion belongs_to :person belongs_to :post

Post has_many :opinions has_many :people, :through => :opinions

Extend from there.

railsdog
  • 1,503
  • 10
  • 10
0

This link helps you alot. Create a new model called Like and relationship with Post

has_many :likes

One more Simple like/unlike button with rails 3, jquery, and ajax

Community
  • 1
  • 1
Sachin R
  • 11,606
  • 10
  • 35
  • 40