Jump to content

The ultimate community for Ruby on Rails developers.


Photo

gem for stamping users via activerecord?

user_stamp stamp_user rails4 activerecord

  • Please log in to reply
1 reply to this topic

#1 Vell

Vell

    Inspector

  • Members
  • 78 posts
  • LocationWashington, DC

Posted 29 April 2014 - 04:13 PM

Hi all,

 

Does anyone know if a gem exists that allows me to stamp users to a record?

 

For instance, I have 2 user fields :created_by and :updated_by and I want to be able to set this to the current user when a record is created.

 

I saw quite a few oudated gems sunch as userstamp and user_stamp but I am wondering if anyone knows of anything that is rails 4 compatible.

 

I am trying to avoid having to have object.created_by = current user or object.updated_by = current_user after the object.new(params[:object]) is created in every controller.



#2 Ohm

Ohm

    Driver

  • Moderators
  • 468 posts
  • LocationCopenhagen

Posted 30 April 2014 - 05:02 AM

You could take a look at - and possible create a pull-request to - one of the gems e.g. https://github.com/delynn/userstamp

 

It seems like they extend the ActiveRecord::Base to include the userstamp methods in a before_save and before_create filter on the model and then using threads get and set the current_user, which wouldn't normally be available at model level.


Blog: http://ohm.sh | Twitter: @madsohm | Work: Lokalebasen.dk






Also tagged with one or more of these keywords: user_stamp, stamp_user, rails4, activerecord

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users