views:

36

answers:

1

Hi, I'm looking the best way to log some of save method call. It will be save in another database. I need to log model and its attributes, and user model, which should be somehow taken from session. How to make it Rails Way?

A: 

this will write a line like this in your log on every save operation:

#<User id: nil, name: "hi", created_at: nil, updated_at: nil>

in the model:

class User <ActiveRecord::Base

before_save :log_attributes

protected
  def log_attributes
    logger.info self.inspect
  end
end
hellvinz
But how to attach user from session in this solution?
Sławosz
I've answered to the "I need to log model and its attributes, and user model" part. The user from session is another thing, it really depends on how you handle your sessions (devise, authlogic, restful_auth...)
hellvinz
I have authlogic
Sławosz