Created
July 25, 2015 21:00
-
-
Save quolpr/7041212a5f267ebd6348 to your computer and use it in GitHub Desktop.
This file contains 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
class ActiveRecord::Base | |
class << do | |
def self.voteable! | |
@voteable = true | |
end | |
def self.voteable? | |
@voteable || false | |
end | |
end | |
end |
This file contains 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
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 |
This file contains 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
class User < ActiveRecord::Base | |
voteable! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment