0.0
No commit activity in last 3 years
No release in over 3 years
Create previews of ActiveRecord objects that don't modify the database
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 5
 Project Readme

ActivePreview

active_preview is a Ruby on Rails plugin that makes it easy to create previews of updates to records. The previews don't interact with the database but otherwise behave like ActiveRecord objects.

Usage

To preview a model, first run the generator:

$ rails generate active_preview:preview --model MyModel

This will create my_model_preview.rb in app/previews. If you have methods that touch the database in your model that need to be used with previewed data, override them there.

Next, add the #preview method to your model:

class MyModel < ActiveRecord::Base
  include ActivePreview::Previewing
end

Now you can pass an attribute hash or ActionController::Parameters object to my_model.preview to get a preview object with updated attributes that behaves exactly like your model.

For models with associations, run the generator for each associated model and add include ActivePreview::Previewing to each model class.

Installation

Add this line to your application's Gemfile:

gem 'active_preview'

And then execute:

$ bundle

Or install it yourself as:

$ gem install active_preview

Contributing

Contribution directions go here.

License

The gem is available as open source under the terms of the MIT License.