Skip to content

Instantly share code, notes, and snippets.

@quolpr
Created July 25, 2015 21:00
Show Gist options
  • Save quolpr/7041212a5f267ebd6348 to your computer and use it in GitHub Desktop.
Save quolpr/7041212a5f267ebd6348 to your computer and use it in GitHub Desktop.
class ActiveRecord::Base
class << do
def self.voteable!
@voteable = true
end
def self.voteable?
@voteable || false
end
end
end
class Likeable
validate :check_voteable
def check_voteable
unless model_type.constantize.voteable?//ну или проверить, если ли у модели belongs_to :likeable связь
errors.add(:model_type, "This model is not voteable")
end
end
end
class User < ActiveRecord::Base
voteable!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment