I use acts_as_versioned to manage versions of Rails models. As I don’t want to create a new version of my document everytime I save it (to fix a typo for instance), I added a virtual attribute called save_with_revision
to my model and put it into the definition of version_condition_met?
.
attr_accessor :save_with_revision
def version_condition_met?
@save_with_revision.to_s[/true|1/] != nil
end
Cool… except that it does not save intermediate updates into the **_versions
table. Let say you create document version 1.0, then update it without creating a new version (from v1.1
to v1.4
) and finally save a new version (v2.0
); v1
will still be v1.0
and not v1.4
.
To save intermediate updates into the **_versions
table, just add to your model:
def after_update
if !version_condition_met? && changed?
versions.find(:last).update_attributes(self.attributes)
end
end
Hope it helps. :)
Anyone with a better solution?
. Bookmark the
permalink. Both comments and trackbacks are currently closed.
Make acts_as_versioned create new version on demand
I use acts_as_versioned to manage versions of Rails models. As I don’t want to create a new version of my document everytime I save it (to fix a typo for instance), I added a virtual attribute called
save_with_revision
to my model and put it into the definition ofversion_condition_met?
.Cool… except that it does not save intermediate updates into the
**_versions
table. Let say you create document version 1.0, then update it without creating a new version (fromv1.1
tov1.4
) and finally save a new version (v2.0
);v1
will still bev1.0
and notv1.4
.To save intermediate updates into the
**_versions
table, just add to your model:Hope it helps. :)
Anyone with a better solution?