Created
June 11, 2018 22:40
-
-
Save graciano/84e0da86ee73dc0951f40167774554a2 to your computer and use it in GitHub Desktop.
module for 'moderatable' models in rails
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 Concerns | |
module Models | |
module Publishable | |
extend ActiveSupport::Concern | |
included do | |
REJECTED = -1 | |
PENDING = 0 | |
PUBLISHED = 1 | |
validates :status, numericality: { | |
less_than_or_equal_to: 1, | |
greater_than_or_equal_to: -1 | |
} | |
default_scope where(status: PUBLISHED) | |
scope :pending_review, -> { where(status: PENDING) } | |
scope :rejected, -> { where(status: REJECTED) } | |
scope :published, -> { where(status: PUBLISHED) } | |
def public? | |
status == PUBLISHED | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment