ruby on rails - Save one attribute for a row in active record -
there 5 ways save new value attribute in activerecord. unfortunately 1 way work , not sure efficient way:
review = review.find(id) review.status = 'ok' review.save!
i started update method, unusual reason deleted review row
review = review.update(id, :status => 'ok) review.save!
any ideas?
the efficient way save new value attribute do:
review.update_attribute(id, :status => 'ok')
there no need phone call save method after because activerecord automatically saves value update_attribute
method.
now, maintain in mind work if alter work if passes validations set on object.
check out link more info:
http://apidock.com/rails/activerecord/base/update/class
ruby-on-rails rails-activerecord
No comments:
Post a Comment