vestal_versions increments version in Rails Console but not through UI

37 Views Asked by At

I have added versioned to my Post model. If I do, for example:

1.9.3-p448 :040 >p = Post.first
1.9.3-p448 :041 > p.version
 => 1 

Then I update the post through our website's UI. I watch the server logs, the changes are saved.

Back on the console:

1.9.3-p448 :054 > p.version
=> 1

No change. But, I do this:

1.9.3-p448 :059 > p.update_attributes(category: "Announcements")
   (1.3ms)  BEGIN
  SQL (2.2ms)  UPDATE "posts" ...
 => true 
1.9.3-p448 :060 > p.version
 => 2

Why does the version update at the command line but not when I update the record through the UI?

1

There are 1 best solutions below

0
On

I think that this is due to the fact that the variable ("p" above) is being assigned a copy of the Post's data, rather than referencing the Post itself. If I reassign my variable to the same object, it appears to reflect the updates made through the UI in the version number. E.g.:

p = Post.find(1)
p.version
=>1

(I then update Post 1 through UI)

p.version
=> 1
p = Post.find(1)
p.version
=> 2