Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. create_table "up_votes", force: true do |t|
  2. t.string "ip"
  3. end
  4.  
  5. create_table "down_votes", force: true do |t|
  6. t.string "ip"
  7. end
  8.  
  9. class Item < ActiveRecord::Base
  10.  
  11. def up_votes_array
  12. self.up_votes.map(&:ip).to_a
  13. end
  14.  
  15. def down_votes_array
  16. self.down_votes.map(&:ip).to_a
  17. end
  18.  
  19. def up_voted?(ip)
  20. self.up_votes_array.include? ip
  21. end
  22.  
  23. def down_voted?(ip)
  24. self.down_votes_array.include? ip
  25. end
  26.  
  27. @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