48
27

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 5 years have passed since last update.

【Rails】newとcreateの違い

Posted at

#newとcreateの違いについて
ActiveRecordの復習をしていて…
newとcreateってどっちもレコードを作るんだよな
どう違うんだろ?と疑問に思ったので調べてみたら単純でした

  • newはオブジュエクトを作成するだけなので、saveもしてあげなくちゃいけない
  • createはnew + save
テーブル名.new
テーブル名.save
テーブル名.create

じゃあcreate使えばいいじゃんと思うのですが、
newでオブジェクトを作った後に条件次第でsaveするか分けたい時に使うのでしょうか?

48
27
2

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
48
27

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?