How to refresh ActiveRecord result in "rails way"? Example:
stuff = Stuff.find(:id)
a = stuff.x # a = 3
(at this time field value in database stuff.x changed to 7 )
a = stuff.x # a = 3 but I need here 7
Is it possible to do something like stuff.refresh_data to re-execute query?
Reloads the attributes of object(here @user) from the database. It always ensures object has latest data that is currently stored in database.
Simply type in the “reload!” command after making changes and the console will reload the session. The “reload!” command is limited in the sense that objects that were instantiated before the reload session will only have access to the initial code prior to any changes.
You can use reload
. In your case you would write stuff.reload
Here is the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With