Adds voting to Rails models to make them sortable by trending (votes weighted against time), or total number of votes.
Vote is library, and auth system agnostic, so no further configuration is needed if:
- Current logged in user is
- Using Devise on User model
- No offset for
rank, which weighs votes against seconds since the Unix Epoch. Setting your own saves a few bits
- Allowing one vote per user, per element
You may optionally define your own epoch. This makes
rank a bit more efficient by reducing the initial baseline for its value length.
> DateTime.now.to_i => 1_418_988_341
then create and add it to an initializer:
# config/initializers/vote.rb Votable.rank_epoch = 1_418_988_341
Allow multiple votes per user, per element
Within the initializer change
Votable.remove_existing_votes from its default value of true:
# config/initializers/vote.rb Votable.remove_existing_votes = false
This will also allow guests to cast (unlimited) votes.
- Each user gets a single vote per element - the latest overwrites any previous
- Voting twice in the same direction on an element removes vote