One thing that keeps me banging my head on the wall in Rails is its unclean way of saving single attributes back to the model. Or at least, my understanding of it.
From what i know, the closest method that is doing that is update_attribute (which is now deprecated?). However, it has a major drawback. It performs an update on all model fields.
If i’m mistaken, please state what is the best way to do this thing in a clean manner. If i’m correct, i seriously don’t understand, why there is not clean method that does this on single attributes?
I just tested this out:
Code:
SQL executed:
So yes, Rails
updatedoes almost what you need. (except that it also updates the updated_at)Tip: In IRB, you can execute
ActiveRecord::Base.logger = Logger.new(STDOUT)to see the log output of Rails (including SQL statments).