acts_as_publishable
====
With acts as publishable, you can turn any model into a publishable model. It provides all the required components that
you need to publish, unpublish, archive or reset a publishable model. Features:
* Auto update status field.
* Auto update/reset published time and archived time.
* i18n support for readiness validation (optional), with publishable scope as shown in the following Step 4.
* Auto generate readiness message errors. When you click on a "not ready" icon, the readiness messages for each record is shown in a "tooltip" like
element.
Example
===
visit http://publishable.continuouslearning.org
more documentation http://www.weebadde.com/
Step 1.
script/plugin install git://github.com/prabode/acts_as_publishable
Step 2.
To create the publishing components under
app/controller
app/views
run
./script/generate publishing
To create the publishing components under admin
app/controller/admin
app/views/admin
run
./script/generate publishing Admin
This will create:
* create app/controllers/admin
* create app/controllers/admin/publishing_controller.rb
* force vendor/plugins/acts_as_publishable/lib/publishable/publishable_helper.rb
* create app/views/admin/publishing
* create app/views/admin/publishing/_publishing_status.rhtml
* create app/views/admin/publishing/_publishing_tooltip.rhtml
* create app/views/admin/publishing/_tooltip_publishing_status.rhtml
* create public/images/admin/publishing
* create public/images/admin/publishing/not_ready.png
* create public/images/admin/publishing/not_ready_small.png
* create public/images/admin/publishing/ready.png
* create public/images/admin/publishing/ready_small.png
* create public/images/admin/publishing/published.png
* create public/images/admin/publishing/published_small.png
* create public/images/admin/publishing/archived.png
* create public/images/admin/publishing/archived_small.png
* create public/images/admin/publishing/arrow.png
* create test/functional/admin
* create test/functional/admin/publishing_controller_test.rb
Step 3.
To use acts_as_publishable, add status* (:string), published_at (:datetime) and archived_at (:datetime) attributes to your model and define :required_fields_for_publishing fields as follows.
During publishing actions, acts_as_publishable will set the status, published_at or archived_at and update your model.
class Video < ActiveRecord::Base
acts_as_publishable :required_fields_for_publishing => [“title”, “channels”, “video_file”, “thumbnails”]
end
*default status_column name is “status” alternatively you can provide a different column name using :status_column, like in the following example.
class Magazine < ActiveRecord::Base
acts_as_publishable :status_column => :stage, :required_fields_for_publishing => [“name”, “description”]
end
Step 4.
If you like to integrate i18n with readiness errors or override the default readiness messages you can use rails i18n module, act_as_publishable look up i18n file for readiness errors in a "publishable" scope, as shown below.
#en.yml file
en:
publishable:
video_title: "This video needs a title."
video_channels: "This video needs at least one 'ready' channel."
video_video_file: "This video needs a video file."
video_thumbnails: "This video needs at least one thumbnail photo."
magazine_name: "Name is required."
magazine_description: "Description is required."
Note:
The i18n key format (example video_title, "#{self.class.name.downcase!}_#{field}") is generated using the model name and the respective field name given in the "required_fields_for_publishing" list.
Step 5.
Include “publishing_status_tag” tag in your views where you need the status and controls to appear.
Here is an example again from our demo app.
admin/videos/show.html.erb
<%= publishing_actions_tag(@video)%>
Step 6.
Review tests for more information.
Copyright © 2009 [Prabode Weebadde, Sharn Jayantha], released under the MIT license