Anyone using vestal_versions:
How do you set the user_id in the versions table?
tried:
in:
def update
@book.version.user_id(@current_user.id)
and
@book.user_id(@current_user.id)
both error
thanks
Anyone using vestal_versions:
How do you set the user_id in the versions table?
tried:
in:
def update
@book.version.user_id(@current_user.id)
and
@book.user_id(@current_user.id)
both error
thanks
this does not work?
@book.version.user_id = @current_user.id ?
Rails error’d on that…
Error “Called id for nil, which would mistakenly be 4 – if you really
wanted the id of nil, use object_id”
that means current user is nil check that out
If I update the code to:
@current_userid = current_user.id
@note.version.user_id = @current_userid
Rails3 seems like that better, the error is now:
undefined method `user_id=’ for 1:Fixnum
@note.version is a number, is the version number, you are pulling the
wrong
property
let me see the railscast to remember how to use it
there is another gem that can help you since it save the user that made
the
change automaticly is called
acts_as_audited
i think it does exactly what you want.
well this gem does not rollback like vestal_versions
oh , ok, i think you can also edit the versions table by altering the
migration that way you can create an association, but im not done
watching
the railscast
Thanks radhames but I’m not trying to implement auditing.
I’m trying to create a wiki like system for books so I have
versioning, which is what vestal_version does. The ‘acts_as_audited’
is more about creating an audit trail of all activity and isn’t about
seeing past versions, reverting etc…
I did find this one post that talks about what I’m trying to get
working:
The thinking is now:
def update
@book.update_attributes(params[:book].merge(:updated_by =>
current_user))
end
It isn’t working yet but I think we’re close :)!
That’s good. Seems to confirm that you can record the updated_by on
updates. The user’s issue in the link was he wants a version for the
1st record created which isn’t something I’m worried about since
that’s in the books table. So some how that user by the updated_by to
work and populate the user_id column in the version table.
first see if ti works without updated_by
Quick update… I think what I’ve been doing wrong is not including
the updated_by current_user in the right place… I now have:
def update
@book = Book.find(params[:id])
respond_to do |format|
if @book.update_attributes(params[:book].merge(:updated_by =>
current_user))
format.html { redirect_to(@book, :notice => ‘Book was
successfully updated.’) }
format.xml { head :ok }
else
format.html { render :action => “edit” }
format.xml { render :xml => @book.errors, :status
=> :unprocessable_entity }
end
end
end
Which doesn’t error HOWEVER it still isn’t populating the right fields
in the VERSIONS table. Any ideas anyone?
Checked that, it does work fine without and with updated_by. Just
doesn’t populate the user_id column
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs