README.md in acts_as_votable-0.12.1 vs README.md in acts_as_votable-0.13.0
- old
+ new
@@ -1,9 +1,8 @@
# Acts As Votable (aka Acts As Likeable)
-[![Build Status](https://travis-ci.org/ryanto/acts_as_votable.svg?branch=master)](https://travis-ci.org/ryanto/acts_as_votable)
-[![Code Climate](https://codeclimate.com/github/ryanto/acts_as_votable.svg)](https://codeclimate.com/github/ryanto/acts_as_votable)
+![Build status](https://github.com/ryanto/acts_as_votable/workflows/CI/badge.svg)
Acts As Votable is a Ruby Gem specifically written for Rails/ActiveRecord models.
The main goals of this gem are:
- Allow any model to be voted on, like/dislike, upvote/downvote, etc.
@@ -22,33 +21,33 @@
### Install
Just add the following to your Gemfile to install the latest release.
```ruby
-gem 'acts_as_votable', '~> 0.12.0'
+gem 'acts_as_votable'
```
And follow that up with a ``bundle install``.
### Database Migrations
Acts As Votable uses a votes table to store all voting information. To
generate and run the migration just use.
rails generate acts_as_votable:migration
- rake db:migrate
+ rails db:migrate
You will get a performance increase by adding in cached columns to your model's
tables. You will have to do this manually through your own migrations. See the
caching section of this document for more information.
## Usage
### Votable Models
```ruby
-class Post < ActiveRecord::Base
+class Post < ApplicationRecord
acts_as_votable
end
@post = Post.new(:name => 'my post!')
@post.save
@@ -191,19 +190,19 @@
### The Voter
You can have your voters `acts_as_voter` to provide some reserve functionality.
```ruby
-class User < ActiveRecord::Base
+class User < ApplicationRecord
acts_as_voter
end
@user.likes @article
-@article.votes.size # => 1
-@article.likes.size # => 1
-@article.dislikes.size # => 0
+@article.votes_for.size # => 1
+@article.get_likes.size # => 1
+@article.get_dislikes.size # => 0
```
To check if a voter has voted on a model, you can use ``voted_for?``. You can
check how the voter voted by using ``voted_as_when_voted_for``.
@@ -272,12 +271,12 @@
```ruby
@user.likes @shoe
@user.likes @shoe
-@shoe.votes # => 1
-@shoe.likes # => 1
+@shoe.votes_for.size # => 1
+@shoe.get_likes.size # => 1
```
To check if a vote counted, or registered, use `vote_registered?` on your model
after voting. For example:
@@ -289,13 +288,13 @@
@hat.vote_registered? # => false, because @user has already voted this way
@hat.disliked_by @user
@hat.vote_registered? # => true, because user changed their vote
-@hat.votes.size # => 1
-@hat.positives.size # => 0
-@hat.negatives.size # => 1
+@hat.votes_for.size # => 1
+@hat.get_positives.size # => 0
+@hat.get_negatives.size # => 1
```
To permit duplicates entries of a same voter, use option duplicate. Also notice that this
will limit some other methods that didn't deal with multiples votes, in this case, the last vote will be considered.
@@ -366,10 +365,10 @@
not by passing `cacheable_strategy` option to `acts_as_votable` method.
By default, `update` strategy is used. Pass `:update_columns` as
`cacheable_strategy` if you don't want to touch model's `updated_at` column.
```ruby
-class Post < ActiveRecord::Base
+class Post < ApplicationRecord
acts_as_votable cacheable_strategy: :update_columns
end
```
NOTE: this option does not work for ActiveRecord < 3.1