diff --git a/lib/paper_trail.rb b/lib/paper_trail.rb index c359a8ce..39103953 100644 --- a/lib/paper_trail.rb +++ b/lib/paper_trail.rb @@ -20,12 +20,14 @@ module PaperTrail !!PaperTrail.config.enabled end - # Returns `true` if PaperTrail is enabled for the controller, `false` otherwise. + # Returns `true` if PaperTrail is enabled for the request, `false` otherwise. + # + # See `PaperTrail::Controller#paper_trail_enabled_for_controller`. def self.enabled_for_controller? !!paper_trail_store[:request_enabled_for_controller] end - # Sets if PaperTrails is disabled by controller + # Sets whether PaperTrail is enabled or disabled for the current request. def self.enabled_for_controller=(value) paper_trail_store[:request_enabled_for_controller] = value end diff --git a/lib/paper_trail/controller.rb b/lib/paper_trail/controller.rb index eaaffa34..1b317f7a 100644 --- a/lib/paper_trail/controller.rb +++ b/lib/paper_trail/controller.rb @@ -39,13 +39,20 @@ module PaperTrail {} end + # Returns `true` (default) or `false` depending on whether PaperTrail should + # be active for the current request. + # + # Override this method in your controller to specify when PaperTrail should + # be off. + def paper_trail_enabled_for_controller + true + end + private - # Tells PaperTrail if version should be saved. + # Tells PaperTrail whether versions should be saved in the current request. def set_paper_trail_enabled_for_controller - if respond_to? :paper_trail_enabled_for_controller - ::PaperTrail.enabled_for_controller = paper_trail_enabled_for_controller - end + ::PaperTrail.enabled_for_controller = paper_trail_enabled_for_controller end # Tells PaperTrail who is responsible for any changes that occur.