0
1

More than 3 years have passed since last update.

【Rails】オブジェクトの更新 save, update_attributes

Last updated at Posted at 2019-11-02

オブジェクトの更新

save

save.rb
user = User.new(name: "new", email: "hoge@example.com")
user.save

作成したオブジェクトを保存する
検証に失敗するとfalseを返す

update_attributes

update_attributes.rb
user.update_attributes(name: "qita", email: "foo@bar.com")

既にあるオブジェクトを更新する
検証に失敗するとfalseを返す

update_attribute

update_attribute.rb
user.update_attribute(name: "qiita")

特定の要素のみ更新し,検証を回避する

参考

第6章 ユーザーのモデルを作成する - Railsチュートリアル

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1