ruby on rails - audited gem: switch between current_user and current_admin -


i using gem audited, logging changes done model. faced problem, when trying distinguish changes being done normal user , being done admin. somehow need tell audited user current_admin method, when current_user nil, can't think of way it.

you can specify method audited gem uses assign user. relavent bit readme below:


current user tracking

if you're using audited in rails application, audited changes made within request automatically attributed current user. default, audited uses current_user method in controller.

class postscontroller < applicationcontroller   def create     current_user # => #<user name: "steve">     @post = post.create(params[:post])     @post.audits.last.user # => #<user name: "steve">   end end 

to use method other current_user, put following in intializer:

audited.current_user_method = :authenticated_user 

in application_controller.rb can add method check nil value in current_user

def current_user_or_admin   current_user || current_admin end 

and in initializer, config/initializers/audited.rb add

audited.current_user_method = :current_user_or_admin 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -