publishable

Rails engine for encapsulating the concept of a publishable resource. Included are:

  • acts_as_publishable extension for models

  • controller to handle tha publishing and unpublishing of resources complete with routes

  • helpers for urls and links

Instalation

Specify it in your Rails config.

config.gem 'aguids-publishable', :lib => 'publishable', :source => 'http://gems.github.com'

Then install it.

rake gems:install

Usage

The first step is to declare a model that acts-as-publishable:

class ListItem < ActiveRecord::Base
  acts_as_publishable
end

Options

The default initial state for publishable models is unpublished. To change that just pass the initial state option:

acts_as_publishable :initial_state => :published

The status column is the default for storing publish status. If you would like to change jus pass the column option:

acts_as_publishable :column => :my_fancy_column

Controller

The publications controller has two actions mapped to it: create and destroy

:resource/:id/publish     #create
:resource/:id/unpublish   #destroy

Remember these are restful, so only posts to create and deletes to destroy are accepted.

If you would like to override the flash messages just define the appropriate translations:

flash:
  publications:
    create:
      notice: 'New publish message.'
    destroy:
      notice: 'New unpublish message.'

Helpers

Route helpers are available

publish_path(post)    # post/post_id/publish

Apart from the route helpers we have the following link helpers:

publication_link(resource)    # Either a link to publish or unpublish
publication_links(resource)   # List with Publish | Unpublish options

To use the helpers just drop the helper call on the applications controller

helper :publications

Copyright © 2009 Felipe Doria. See LICENSE for details.