vestal_versions
vestal_versions copied to clipboard
Can't record user for the creation of versioned records.
So, I want to record the user who submits each version change, But if I try and do this via the vestial_versions :updated_by I can't record the creator (I presume because no version is recorded for the first version... SO any chance to make this recording an option, I I can work around it by just recording a 'created_by' but in that case i might as well record a 'modified_by' and just always use that field on my record rather than vestial versions clever updated_by field... I removing version=1 was probably being too clever with resource usage! maybe make it switchable?
Cheers, James
+1 I'm importing from a legacy system and need to record the user details for the person who created the original version.
I've had a crack at doing this. Please check out my fork: http://github.com/schlick/vestal_versions/tree/initial-version
So by setting versioned initial_version => true in your model, all new objects will automatically have a version=1 created. Although it contains nil changes you can use it for storing information about the user who created the record.
Using it in my project, I am now able to simply set foo.updated_by("bar") and foo.versions.first.user will return "bar".
Prior to this I had used:
if foo.versions.empty?
foo.versions << VestalVersions::Version.new(:user_name => name), :number => 1)
else
foo.updated_by = name
end
Excellent fork, please merge this into the main vestal_versions.
How do you get the vestial_versions :updated_by to work when updating a record? I'd like to record the user_id on every version record. thanks
Check out the readme for a full description but in a nutshell all you need to do is:
@user.update_attributes(:last_name => "Jobs", :updated_by => current_user)
You can either pass it a User object or a string.
This works for each new version you create but not the initial version (that's what the changes in my fork adds).
schlick, thanks for the reply (I've been stuck on this for days, so highly appreciated). Right now I'm using the Rails 3 fork here: "gem 'vestal_versions', :git => 'git://github.com/lailsonbm/vestal_versions', :branch => 'rails3'"
I have a controller for books, and I would like updated_by to take effect whenever a book is updated. So I've tried the following w/o any success. Any ideas?
http://pastebin.com/uHxzNgHC
Thanks
Sorry bhellman1, I haven't investigated using vestal versions with Rails 3 yet. It's good to see that someone has created a fork and is working on a Rails 3 compatible version. I wonder whatever happened to laserlemon?
That's to bad, if it were Rails 2+ would the pastebin code work fine? Just curious if it's my code or vestal_version's fork..... Re laserlemon, according to his Twitter: http://twitter.com/laserlemon/status/24332546385
Just wanted to chime in here that there is an active Rails 3 fork that I've been maintaining and pulled in several of the outstanding changes in forks including the initial_version fork.
You can find it here: https://github.com/adamcooper/vestal_versions
bhellman1: I tried the :updated_by from my fork and it seems to work in the console with and without the initial_versions option.
Thanks, Adam
@Adam, thanks! You're a real mench. I'll try that this afternoon... Random (kinda), have you ever gotten paperclip to work with Vestal_Versions, so that when you update images they aren't deleted but stored as versions? thanks again!
In fact, I have dealt with paperclip and vestal_versions on my project.
I've posted up the relevant parts here: https://gist.github.com/667933
Let me know if you have any questions.
Cheers, Adam