Isnor Creative
Isnor Creative Blog
Ruby, Ruby on Rails, Ember, Elm, Phoenix, Elixir, React, Vue

Apr 9, 2009

acts_as_versioned_with_changes

Acts As Versioned is a very cool gem from technoweenie that will store versioned copies of your main table in a secondary _versions table. One problem I noticed in trying to get it running was that running sudo gem install acts_as_versioned grabbed what appeared to be a very old copy which failed miserably with Rails 2.3 due to the older version not being compatible with the new ‘dirty’ object functionality added in Rails 2.1, so I found I had to clone it from the github repo: http://github.com/technoweenie/acts_as_versioned.

I was quoting on a project that required a log of changes made from version to version, so I forked the gem and made some modifications…. My fork takes advantage of the aforementioned ‘dirty’ object feature to create a serialized ‘changes’ column, so when you are working with a version you also have access to a version.changes hash which you can use to do something like this:

<% version.changes.each_pair do |key,values| %>
  Field: <%= key >
  Original: <%= values.first %>
  Updated: <%= value.last %>
<% end %>

Get it here: git clone git://github.com/gordonbisnor/acts_as_versioned_with_changes.git


I am available for Ruby on Rails consulting work – get in touch to learn more.

Gordon B. Isnor

Gordon B. Isnor writes about Ruby on Rails, Ember.js, Elm, Elixir, Phoenix, React, Vue and the web.
If you enjoyed this article, you may be interested in the occasional newsletter.

I am now available for project work. I have availability to build greenfield sites and applications, to maintain and update/upgrade existing applications, team augmentation. I offer website/web application assessment packages that can help with SEO/security/performance/accessibility and best practices. Let’s talk

comments powered by Disqus