README.md in acts_as_votable-0.13.1 vs README.md in acts_as_votable-0.13.2
- old
+ new
@@ -49,11 +49,11 @@
```ruby
class Post < ApplicationRecord
acts_as_votable
end
-@post = Post.new(:name => 'my post!')
+@post = Post.new(name: 'my post!')
@post.save
@post.liked_by @user
@post.votes_for.size # => 1
```
@@ -64,13 +64,13 @@
more natural calls are the first few examples.
```ruby
@post.liked_by @user1
@post.downvote_from @user2
-@post.vote_by :voter => @user3
-@post.vote_by :voter => @user4, :vote => 'bad'
-@post.vote_by :voter => @user5, :vote => 'like'
+@post.vote_by voter: @user3
+@post.vote_by voter: @user4, vote: 'bad'
+@post.vote_by voter: @user5, vote: 'like'
```
By default all votes are positive, so `@user3` has cast a 'good' vote for `@post`.
`@user1`, `@user3`, and `@user5` all voted in favor of `@post`.
@@ -84,16 +84,16 @@
Revisiting the previous example of code.
```ruby
# positive votes
@post.liked_by @user1
-@post.vote_by :voter => @user3
-@post.vote_by :voter => @user5, :vote => 'like'
+@post.vote_by voter: @user3
+@post.vote_by voter: @user5, vote: 'like'
# negative votes
@post.downvote_from @user2
-@post.vote_by :voter => @user2, :vote => 'bad'
+@post.vote_by voter: @user2, vote: 'bad'
# tally them up!
@post.votes_for.size # => 5
@post.weighted_total => 5
@post.get_likes.size # => 3
@@ -140,55 +140,55 @@
You can add a scope to your vote
```ruby
# positive votes
-@post.liked_by @user1, :vote_scope => 'rank'
-@post.vote_by :voter => @user3, :vote_scope => 'rank'
-@post.vote_by :voter => @user5, :vote => 'like', :vote_scope => 'rank'
+@post.liked_by @user1, vote_scope: 'rank'
+@post.vote_by voter: @user3, vote_scope: 'rank'
+@post.vote_by voter: @user5, vote: 'like', vote_scope: 'rank'
# negative votes
-@post.downvote_from @user2, :vote_scope => 'rank'
-@post.vote_by :voter => @user2, :vote => 'bad', :vote_scope => 'rank'
+@post.downvote_from @user2, vote_scope: 'rank'
+@post.vote_by voter: @user2, vote: 'bad', vote_scope: 'rank'
# tally them up!
-@post.find_votes_for(:vote_scope => 'rank').size # => 5
-@post.get_likes(:vote_scope => 'rank').size # => 3
-@post.get_upvotes(:vote_scope => 'rank').size # => 3
-@post.get_dislikes(:vote_scope => 'rank').size # => 2
-@post.get_downvotes(:vote_scope => 'rank').size # => 2
+@post.find_votes_for(vote_scope: 'rank').size # => 5
+@post.get_likes(vote_scope: 'rank').size # => 3
+@post.get_upvotes(vote_scope: 'rank').size # => 3
+@post.get_dislikes(vote_scope: 'rank').size # => 2
+@post.get_downvotes(vote_scope: 'rank').size # => 2
# votable model can be voted under different scopes
# by the same user
-@post.vote_by :voter => @user1, :vote_scope => 'week'
-@post.vote_by :voter => @user1, :vote_scope => 'month'
+@post.vote_by voter: @user1, vote_scope: 'week'
+@post.vote_by voter: @user1, vote_scope: 'month'
@post.votes_for.size # => 2
-@post.find_votes_for(:vote_scope => 'week').size # => 1
-@post.find_votes_for(:vote_scope => 'month').size # => 1
+@post.find_votes_for(vote_scope: 'week').size # => 1
+@post.find_votes_for(vote_scope: 'month').size # => 1
```
### Adding weights to your votes
You can add weight to your vote. The default value is 1.
```ruby
# positive votes
-@post.liked_by @user1, :vote_weight => 1
-@post.vote_by :voter => @user3, :vote_weight => 2
-@post.vote_by :voter => @user5, :vote => 'like', :vote_scope => 'rank', :vote_weight => 3
+@post.liked_by @user1, vote_weight: 1
+@post.vote_by voter: @user3, vote_weight: 2
+@post.vote_by voter: @user5, vote: 'like', vote_scope: 'rank', vote_weight: 3
# negative votes
-@post.downvote_from @user2, :vote_scope => 'rank', :vote_weight => 1
-@post.vote_by :voter => @user2, :vote => 'bad', :vote_scope => 'rank', :vote_weight => 3
+@post.downvote_from @user2, vote_scope: 'rank', vote_weight: 1
+@post.vote_by voter: @user2, vote: 'bad', vote_scope: 'rank', vote_weight: 3
# tally them up!
-@post.find_votes_for(:vote_scope => 'rank').sum(:vote_weight) # => 6
-@post.get_likes(:vote_scope => 'rank').sum(:vote_weight) # => 6
-@post.get_upvotes(:vote_scope => 'rank').sum(:vote_weight) # => 6
-@post.get_dislikes(:vote_scope => 'rank').sum(:vote_weight) # => 4
-@post.get_downvotes(:vote_scope => 'rank').sum(:vote_weight) # => 4
+@post.find_votes_for(vote_scope: 'rank').sum(:vote_weight) # => 6
+@post.get_likes(vote_scope: 'rank').sum(:vote_weight) # => 6
+@post.get_upvotes(vote_scope: 'rank').sum(:vote_weight) # => 6
+@post.get_dislikes(vote_scope: 'rank').sum(:vote_weight) # => 4
+@post.get_downvotes(vote_scope: 'rank').sum(:vote_weight) # => 4
```
### The Voter
You can have your voters `acts_as_voter` to provide some reserve functionality.
@@ -299,11 +299,11 @@
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.
```ruby
-@hat.vote_by voter: @user, :duplicate => true
+@hat.vote_by voter: @user, duplicate: true
```
## Caching
To speed up perform you can add cache columns to your votable model's table. These
@@ -350,10 +350,10 @@
`cached_weighted_average` can be helpful for a rating system, e.g.:
Order by average rating:
```ruby
-Post.order(:cached_weighted_average => :desc)
+Post.order(cached_weighted_average: :desc)
```
Display average rating:
```erb