Last active
December 13, 2017 15:59
-
-
Save salami-art/8a56e5dc5fe9bbe5f8b2f43d416d353a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Rateable | |
def self.included(base) | |
base.class_eval do | |
attribute :average_rating | |
attribute :ratings_total | |
has_many :all_ratings, foreign_key: "#{self.class.name}_id", class_name: 'Rating' # class_name should be the included class name but returns 'Class'instead | |
has_many :published_ratings, -> { where(:status => Rating::STATUSES[:PUBLISHED])}, foreign_key: "#{self.class.name}_id", class_name: "Rating" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment