0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

備忘録:「saveメソッド」と「save!メソッド」の違い

Last updated at Posted at 2022-01-02

saveメソッドとは

DBにデータを保存するメソッド。(インスタンスメソッドです。)

※ちなみにsaveはActiveRecordの基本メソッドです。

「saveメソッド」と「save!メソッド」の違い

saveメソッド:
保存に成功した場合→trueを返す
保存に失敗した場合→falseを返す
※saveメソッドを使う場合は、if/else文で「保存できた場合」と「保存できなかった場合」とで処理をわけると良い。

save!メソッド:
保存に成功した場合→trueを返す
保存に失敗した場合→例外を発生させる
※保存に失敗した場合の処理はrescue節で行う必要がある。

引用元:
https://techacademy.jp/magazine/22082
http://www.code-magagine.com/?p=9275

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?