- Most Recent |
24 hours |
7 days |
30 days |
365 days |
HowFlow —
The Ruby on Rails plugin userstamp automatically sets created_by and updated_by and works much like the ActiveRecord::Timestamp module (created_at and updated_at). But when you try to save a record on the Rails console, it suddenly returns an error.
Posted by
aroedl 2 months ago
aroedl 2 months ago The Userstamp Plugin
If you don’t know what the plugin in does, have a look at the project site
The Userstamp Plugin extends ActiveRecord::Base to add automatic updating of ‘creator’, ‘updater’, and ‘deleter’ attributes. It is based loosely on the ActiveRecord::Timestamp module.
Problem
If you now try to save a stampable record on the console, you get an error message:
>> myobject.save
ActiveRecord::RecordNotFound: Couldn't find User without an ID
from /project/vendor/rails/activerecord/lib/active_record/base.rb:1262:in `find_from_ids'
from /project/vendor/rails/activerecord/lib/active_record/base.rb:503:in `find'
from /project/vendor/plugins/userstamp/lib/stamper.rb:31:in `stamper'
from /project/vendor/plugins/userstamp/lib/stampable.rb:121:in `has_stamper?'
from /project/vendor/plugins/userstamp/lib/stampable.rb:133:in `set_updater_attribute'
Solution
As soon as we set the stamper, everything works as expected:
>> User.stamper = User.find(1)
>> myobject.save
=> true
Please log in or sign up and vote for this trick if it was helpful for you.
Don't forget to subscribe to our
RSS/Atom feed to get the latest tricks.
Don't forget to subscribe to our
RSS/Atom feed to get the latest tricks.









