Method: PaperTrail::Model::ClassMethods#has_paper_trail
- Defined in:
- lib/paper_trail/has_paper_trail.rb
#has_paper_trail(options = {}) ⇒ Object
Declare this in your model to track every create, update, and destroy. Each version of the model is available in the versions association.
Options:
-
:on - The events to track (optional; defaults to all of them). Set to an array of
:create,:update,:destroyas desired. -
:class_name - The name of a custom Version class. This class should inherit from
PaperTrail::Version. -
:ignore - An array of attributes for which a new
Versionwill not be created if only they change. It can also aceept a Hash as an argument where the key is the attribute to ignore (aStringorSymbol), which will only be ignored if the value is aProcwhich returns truthily. -
:if, :unless - Procs that allow to specify conditions when to save versions for an object.
-
:only - Inverse of
ignore. A newVersionwill be created only for these attributes if supplied it can also aceept a Hash as an argument where the key is the attribute to track (aStringorSymbol), which will only be counted if the value is aProcwhich returns truthily. -
:skip - Fields to ignore completely. As with
ignore, updates to these fields will not create a newVersion. In addition, these fields will not be included in the serialized versions of the object whenever a newVersionis created. -
:meta - A hash of extra data to store. You must add a column to the
versionstable for each key. Values are objects or procs (which are called withself, i.e. the model with the paper trail). SeePaperTrail::Controller.info_for_paper_trailfor how to store data from the controller. -
:versions - The name to use for the versions association. Default is
:versions. -
:version - The name to use for the method which returns the version the instance was reified from. Default is
:version. -
:save_changes - Whether or not to save changes to the object_changes column if it exists. Default is true
-
:join_tables - If the model has a has_and_belongs_to_many relation with an unpapertrailed model, passing the name of the association to the join_tables option will paper trail the join table but not save the other model, allowing reification of the association but with the other models latest state (if the other model is paper trailed, this option does nothing)
64 65 66 |
# File 'lib/paper_trail/has_paper_trail.rb', line 64 def has_paper_trail( = {}) paper_trail.setup() end |