Quickly add published/drafted states to your ActiveRecord models, with helpful scopes and instance methods for querying and changing the states
Add this line to your application's Gemfile:
gem 'pubdraft'
And then execute:
$ bundle
Or install it yourself as:
$ gem install pubdraft
# requires string column `state` to exist
# $ rails g migration AddStateToMyModels state
class MyModel < ActiveRecord::Base
pubdraft
end
record = MyModel.create!
record.published? #=> true
record.draft!
record.drafted? #=> true
record.publish!
record.published? #=> true
MyModel.published #=> [published records]
MyModel.drafted #=> [drafted records]
The gem provides a view helper to easily populate select boxes
<!-- Standard Form Helpers -->
<%= form_for @record do |f| %>
<%= f.select :state, pubdraft_state_options %>
<% end %>
<!-- Formtastic -->
<%= semantic_form_for @record do |f| %>
<%= f.input :state, :collection => pubdraft_states_for_select, :as => :select %>
<% end %>
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request