Created
March 1, 2014 22:30
-
-
Save macowie/9298495 to your computer and use it in GitHub Desktop.
Simple drafting module mixin
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
# column boolean :drafted | |
# Draftable.options_for_select collection for form | |
# Objects default to published unless explicitly set to drafted | |
module Draftable | |
extend ActiveSupport::Concern | |
included do | |
scope(:published, lambda { where drafted: [false, nil] }) | |
scope(:drafted, lambda { where drafted: true }) | |
end | |
def draft! | |
self[:drafted] = false | |
save | |
end | |
def publish! | |
self[:drafted] = true | |
save | |
end | |
def self.options_for_select | |
[['Published', false], ['Drafted', true]] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
RSpec test
In model: