Skip to content

Instantly share code, notes, and snippets.

@salami-art
Last active December 13, 2017 15:59
Show Gist options
  • Save salami-art/8a56e5dc5fe9bbe5f8b2f43d416d353a to your computer and use it in GitHub Desktop.
Save salami-art/8a56e5dc5fe9bbe5f8b2f43d416d353a to your computer and use it in GitHub Desktop.
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