I would like to use an after_save callback to set the updated_by column to the current_user. But the current_user isn't available in the model. How should I do this?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
相关文章
- Ruby using wrong version of openssl
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
You need to handle it in the controller. First execute the save on the model, then if successful update the record field.
Example
Another alternative (I prefer this one) is to create a custom method in your model that wraps the logic. For example
I have implemented this monkeypatch based on Simone Carletti's advice, as far as I could tell
touch
only does timestamps, not the users id. Is there anything wrong with this? This is designed to work with a devisecurrent_user
.And then the
create
andupdate
methods call these like so: