LoginSignup
2
1

More than 5 years have passed since last update.

Rails Tutorial メモvol.3

Last updated at Posted at 2015-03-26

第6章 新規ユーザーの登録

rails console上で
user1=User.new(name:"~",email:"~")

コマンドで、メモリ上にuser1のデータを作成する。(※DB上には保存されていない)

ここで
user1.save
を実行することにより、DB上にも保存される。
この際に、id,created_at,updated_at属性が生成される。

この一連の操作を
user1=User.create(name:"~",email:"~")
で行える。

・DB上から削除
user1.destroy
ただし、メモリには残ってる。
・DB上のデータの確認(検索)
User.find(@id)
でid=@idのユーザーを探せる。
destroyしたユーザーは検索できなくなっている。
・登録されているユーザーの表示
User.all <--全員表示
User.first <--idが一番若いものを表示

2
1
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
2
1