A DataMapper compatible voting gem. Can track votes by identifier so a user may only submit a single vote.
- Ruby 1.9
To install as a gem add the following line to your gem file.
gem 'dm-is-voteable'
Then:
bundle install
And build the required DB tables:
rake db:auto_update
Add is_voteable
To any model and gain the power of the vote method.
class Movie
include DataMapper::Resource
property :id, Serial
property :title, String, required: true
is_voteable
end
Vote for the Model by calling model.vote
Allow only a single vote per user within a certain time frame by setting a time frame in the model:
class Movie
include DataMapper::Resource
property :id, Serial
property :title, String, required: true
is_voteable(last_vote_time: ->{ 3.days.ago })
end
Then send an identifier along with the vote:
user_ip = request.env['REMOTE_ADDR']
model.vote(user_ip)