I want to add a “like” functionality to a blog I am creating in Ruby on Rails to let people “thumbs up” a post. Then I would like to be able to display the most liked posts in the side bar. I am new to rails so rely heavily on tutorials and stack overflow. Any good resources or what is this even called. I assumed “voting” for this question.
Share
You should look up link_to_remote and using AJAX with rails. Here is a nice tutorial to get started: http://railsonedge.blogspot.com/2008/03/tutorial-beginning-ajax-with-rails-20.html
The idea would be:
The user clicks on “vote”
It sends an asynchronous message to the controller to save the vote. (use
link_to_remote)the :complete callback does something (eg “thanks for voting!”)
the :update changes the voting zone (eg “voted. 6 votes on this”)
There are a lot of tutorials on the subject.
EDIT: I wrote that a while ago and since then the best practices have changed. Now please take a look at how to do that using unobstrusive javascript. Good resources include Ryan Bates Bates’s railscast #205 and the wikipedia article to understand the principle.