Skip to content

First save ignores :if condition #11

Simbul opened this Issue Oct 13, 2011 · 3 comments

2 participants

Simbul commented Oct 13, 2011

When saving a versioned model for the first time, a version is created regardless of the :if condition.

E.g. if I do

acts_as_versioned :if => {|item| false}

I will still get a new record in the _versions table when calling the first save() (or create()) on my model.

I suppose there's a reason for this, but from my point of view when the :if condition is false no version should be saved, ever.

I think the behavior stems from line 391 in acts_as_versioned.rb.

@saving_version = new_record? || save_version?

Why do new records get to bypass the version saving conditions?


I dont remember... I guess so there's always an initial versioned record? I can't believe anyone still uses this :)

Simbul commented Oct 13, 2011

According to my tests it is possible to honour the :if condition and still get correct results. I'll submit a pull request momentarily.

While we're at it, do you know of any other gem that does the same job as yours and is actively supported? :)


Nope. I'm sure there's something out there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.