Class: ActsRateable::Rate

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/acts_rateable/rate.rb

Class Method Summary collapse

Class Method Details

.create(author, resource, value) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/acts_rateable/rate.rb', line 29

def self.create(author, resource, value)
  return unless author && resource && value
      atts = { 
 resource_type: resource.class.base_class.name, resource_id: resource.id,
 author_type: author.class.base_class.name, author_id: author.id,
 value: value
      }
      rate = where(atts.except(:value)).first_or_initialize(atts)
      rate.value = value
  rate.save
  return rate
end

.rated?(resource, author) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
# File 'lib/acts_rateable/rate.rb', line 20

def self.rated?(resource, author)
  rate = where({
    author_type: author.class.base_class.name, author_id: author.id,
    resource_type: resource.class.base_class.name, resource_id: resource.id
  })
  return rate if rate
  return false
end