"Best practice" for accessing session from model

i need to do update pm a "updated_by" field with a session variable "user" on a model after_save.

but accessing session variables from models is supposedly bad

whats the usual best practice for this kinda scenario ?

i need to do update pm a "updated_by" field with a session variable "user" on a model after_save.

but accessing session variables from models is supposedly bad

ActiveRecord shouldn't know anything about the controller/view environment... it only knows how to deal with information that has been passed to it.

whats the usual best practice for this kinda scenario ?

So the best option is to pass the data to ActiveRecord. There are a number of ways that you could do this. You could do this through your users model. You might look at Userstamp for inspiration:

* GitHub - delynn/userstamp: This Rails plugin extends ActiveRecord::Base to add automatic updating of created_by and updated_by attributes of your models in much the same way that the ActiveRecord::Timestamp module updates created_(at/on) and updated_(at/on) attributes.

Best of luck!

Cheers, Robby

Thanks

totally got lost ploughing thru Userstamp's code probably a good time for me to start learning some metaprogramming

Lin Wj wrote:

Thanks

totally got lost ploughing thru Userstamp's code probably a good time for me to start learning some metaprogramming

Not that I spend much time digging though the code of Userstamper myself, but I believe this this the key to what makes the magic happen: