Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create_table "up_votes", force: true do |t|
- t.string "ip"
- end
- create_table "down_votes", force: true do |t|
- t.string "ip"
- end
- class Item < ActiveRecord::Base
- def up_votes_array
- self.up_votes.map(&:ip).to_a
- end
- def down_votes_array
- self.down_votes.map(&:ip).to_a
- end
- def up_voted?(ip)
- self.up_votes_array.include? ip
- end
- def down_voted?(ip)
- self.down_votes_array.include? ip
- end
- @not_voted = Thing.where(show: true).select { |item| !item.up_voted?(request.remote_ip) }.select { |thing| !item.down_voted?(request.remote_ip) }.sort_by(&:alphabetical).reverse.first(100).shuffle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement