It’s nice to have properties, but it would be even nicer if we could easily enable versioning. This is very easy: you just need to specify the name of a method to reach the model that will hold the properties storage. Here is an example that uses the brand new Versions gem:
class Contact < ActiveRecord::Base include Versions::Multi has_multiple :versions include Property store_properties_in :version property do |t| t.string 'name', :indexed => true t.string 'first_name' t.integer 'age' t.datetime 'seen_at', :default => Proc.new { Time.now } end end
Your Version
model would look like this:
class Version < ActiveRecord::Base include Versions::Auto def should_clone? true # always clone on update end end
And that’s it. You can use the Contact class as if it had ‘name’ and ‘first_name’ attributes and the content will be transparently versioned.