Publications is a library for Rails, enabling you to easily add publication control to your models. You can control publication based on activation and deactivation dates, a boolean flag, or a combination of both.
Support is included for CRUD runtime generators (such as ActiveAdmin, ActiveScaffold)
Just add this to your Gemfile:
gem "publications"(you can also install the gem directly with: gem install publications)
After Publications is installed, it's easy to add publication support to your models. Just add this to your class:
has_publish_controlExample:
class Book
has_publish_control # This is all it takes :)
endYou'll be able to do the following:
book = Book.new
book.active = true
book.activated_at = 10.days.from_now
book.disabled_at = 20.days.from_now
book.save!
Book.active # will return all active books
Book.all # will return only published books, if creation of a global scope has been enabledA few columns will be needed in your tables to handle publications. To add them, just add the following to your migrations (either on createtable or changetable):
t.publicationsExample
class AddPublicationsToBooks < ActiveRecord::Migration
def self.up
create_table :books do |t|
t.publications
end
end
def self.down
#TODO
end
endThe following options allow you to configure Publications to fit your needs:
:default_scope Configures wether a default scope is created that only returns published objects (default = false)
The project includes helpers for a few CRUD runtime generators (such as ActiveAdmin, ActiveScaffold).
To use with ActiveAdmin, include the following in your form configuration:
f.inputs "Publication" do
f.publications
endTo use with ActiveScaffold, include the following in your form configuration:
TBD
Significant improvements
- Support for publication workflow (aprovals)
- Support for other conditions besides dates and boolean flag
- Support for configurable publishing conditions
- Support for users and groups (publish for just a given set of people)
- Integration with fine-grained access control framework
Small improvements
- Add ActiveScaffold support (and eventually RailsAdmin)
- Add more tests
- Implement down migrations
- Add indexes
- Default scopes
- More configuration options
Copyright © 2013 Runtime Revolution, released under the MIT license.