views:

42

answers:

1

I'm trying to modify the vestal_versions plugin to accept a parameter I set upon saving. This parameter will act as a new flag to determine when to create a revision upon updating. Currently it will always run upon update when a new revision is needed. Here is the affected area of unmodified plugin code:

after_update :create_version, :if => :needs_version?

    def create_version
     versions.create(:changes => changes.slice(*versioned_columns), :number => (last_version + 1))
     reset_version
    end

The parameter I am sending in the view upon submit is "forcerevision=n". How would I pull in this parameter and what conditional would I use to allow this to only run when "forcerevision=y"? It seems it would be cleanest to modify the after_update filter?

Here is the log of the data being passed on update.

Processing NotesController#update (for 521.0.0.1 at 2009-12-05 13:25:45) [PUT]
Parameters: {"authenticity_token"=>"#########################+k=", "id"=>"4", "forcerevision"=>"n", "note"=>{"notebook_id"=>"", "public"=>"n", "body"=>"A versioned note", "title"=>"Version Note Test", "flag"=>"important", "star"=>"false", "tag_list"=>""}}

vestal_versions on Github

A: 
EmFi
Thanks so much for the in-depth answer. It worked perfectly! Just so I can understand this a bit better, why does the attr_accessor need to be placed in the location specified and not for example in LaserLemon::VestalVersions?
Westing
It's got to do with the way modules are processed on include. When the plugin is loaded it modifies all descendants of ActiveRecord::Base. By placing it in the LaserLemon::VestalVersions::ClassMethods#versioned the attr\_accessor is only added to models that need it.
EmFi
Thanks, that makes sense.
Westing