Img source: instructables.com/

The ability to rapidly develop new features in your Rails applications with a lot of cool gems gives you the opportunity to be very productive. At the time of this writing, 14,821,263,017 Ruby gems have been downloaded, which represents a really large number of developers who have fortunately been able to use open source gems of other fellow developers in their applications. Acts as Votable is no exception.

If you have a model in your Rails application in which you need to add the ability to like/dislike, upvote/downote, then there is a really good gem that you can use. It is called Acts as Votable.

You can install it by adding the following in your Gemfile:


gem 'acts_as_votable', '~> 0.10.0'

You can learn more about the way you can install this gem by visiting this README in case you read this later when new versions come up.

As this will add a new entity column in your database, you will have to generate a new migration and then run it:


rails generate acts_as_votable:migration


rake db:migrate

Then you can simply add the following line at your model:

acts_as_votable

You can use it in any particular scenario of your choice, but let’s briefly mention a few to make it clearer why it is worth considering.

If you are building a mini-social network, in which users can post new statuses, then you may use this gem. As a result, other people can upvote or downvote a status, which can then show the popularity of particular statuses.

Let’s take another example. Let’s say that you have a project management application, in which many team members are allowed to suggest their ideas about certain aspects of the projects that you work on. You use this gem as a way for your team members to vote for other members suggestions. This gives you a way to find out which opinion is the most accepted by then sorting these projects based on the votes given.

Here are a few examples demonstrating how you can use it:

@project.liked_by @user1

@project.unliked_by @user2
That’s pretty cool, right?

You can learn more about usage cases demonstrated here. I hope you like this gem and have it in your gem list that you consider to use in your projects.