Module: Votes::ActiveRecordExt::VoteableInstanceMethods
- Defined in:
- lib/votes/active_record_ext.rb
Instance Method Summary collapse
- #recalculate_rating ⇒ Object
- #update_rating(vote) ⇒ Object
- #vote_by_current_visitor(current_user, session) ⇒ Object
- #vote_by_session_key(session_key) ⇒ Object
- #vote_by_user(user) ⇒ Object
Instance Method Details
#recalculate_rating ⇒ Object
47 48 49 |
# File 'lib/votes/active_record_ext.rb', line 47 def self.update_attribute(:rating, self. + self.votes.map(&:points).sum) end |
#update_rating(vote) ⇒ Object
43 44 45 |
# File 'lib/votes/active_record_ext.rb', line 43 def (vote) self.update_attribute(:rating, self. + vote.points) end |
#vote_by_current_visitor(current_user, session) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/votes/active_record_ext.rb', line 27 def vote_by_current_visitor current_user, session if current_user vote_by_user(current_user) else vote_by_session_key(session) end end |
#vote_by_session_key(session_key) ⇒ Object
39 40 41 |
# File 'lib/votes/active_record_ext.rb', line 39 def vote_by_session_key session_key self.votes.find_by_session_key(session_key) end |
#vote_by_user(user) ⇒ Object
35 36 37 |
# File 'lib/votes/active_record_ext.rb', line 35 def vote_by_user user self.votes.find_by_user_id(user.id) end |