Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Make an ActiveRecord object previewable, and display the preview using existing/custom templates

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 pkg
Octocat-spinner-32 rails
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 MIT-LICENSE
Octocat-spinner-32 Rakefile
Octocat-spinner-32 install.rb
Octocat-spinner-32 preview.gemspec
Octocat-spinner-32 uninstall.rb


Make an ActiveRecord object preview-able, and display the preview using existing/custom templates


gem install preview


Within controller:


This will enable preview generation for the resource that is handled by the controller (eg: post for PostsController)

Within view-form:


Will generate a preview button, on pressing which, the preview opens in a new tab.
(f is the form object for the model.)

More options:

previewable :actions => [:mycreate]

The preview functionality works for forms that submit to the mycreate action, instead of the default (create, update)

previewable :template => "myshow"  

The preview is generated using the myshow.html.erb template instead of the default (show.html.erb)

How it works:

When the form is submitted through the preview button, it sends all the form values to the create/update actions on the server. This gem adds a before_filter to those actions, where it creates the resource instance variable (@post for PostsController) using the passed values, and then renders the template using the instance variable.


The resource preview object is not persisted - no data is written to the database.

Something went wrong with that request. Please try again.