Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One-liner searched in Ruby on Rails for altering attribute in database

In Ruby on Rails, for an ActiveRecord class MySettings, is there a more elegant option to say

s = MySettings.last
s.do_updates = true
s.save

in one line?

like image 598
Yo Ludke Avatar asked Nov 30 '25 16:11

Yo Ludke


2 Answers

Use update_attributes:

  MySettings.last.update_attributes :do_updates => true
like image 100
Rahul Tapali Avatar answered Dec 02 '25 05:12

Rahul Tapali


update_attributes

MySettings.last.update_attributes(:do_updates => true)
like image 23
jdl Avatar answered Dec 02 '25 07:12

jdl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!