I implemented this monkeypatch based on the advice of Simone Carletti, as far as I could tell, touch only has timestamps, not user identifiers. Is there something wrong with this? This is intended to work with the current_user device.
class ActiveRecord::Base def save_with_user(user) self.updated_by_user = user unless user.blank? save end def update_attributes_with_user(attributes, user) self.updated_by_user = user unless user.blank? update_attributes(attributes) end end
And then the create and update methods call them like this:
@foo.save_with_user(current_user) @foo.update_attributes_with_user(params[:foo], current_user)
source share