Skip to content

Instantly share code, notes, and snippets.

@graciano
Created June 11, 2018 22:40
Show Gist options
  • Save graciano/84e0da86ee73dc0951f40167774554a2 to your computer and use it in GitHub Desktop.
Save graciano/84e0da86ee73dc0951f40167774554a2 to your computer and use it in GitHub Desktop.
module for 'moderatable' models in rails
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