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

Usersリソースを作成する

Posted at

Railsチュートリアルの2章を勉強した。

rails generate scaffold User name:string email:string

いろんなファイルが作られたり、既存のデータに追加されたりする

c9 ファイル名

ファイルを開くことができる

rails db:migrate

単にデータベースを更新し、usersデータモデルを作成するためのもの

rails routes

どこにアクセスすれば何があるのかを教えてくれる

ユーザーページを探索する

rails serverのurlにrails routesに書かれているルートを入力するとそのページに移動することができる。

MVCの挙動

1,
ブラウザからurlのリクエストをRailsサーバーに送信する

2,
リクエストは、RailsのルータによってUsersコントローラ内にrails routesに書いてあるアクションindexに割り当てられる

3,
indexアクションが実行される。User.all (全てのユーザを取り出す)でUserモデルに問い合わせる。

4,
全てのuserモデルのユーザーのデータベースから取り出す

5,
indexアクションの@userに返す

6,
indexビューが起動する HTMLを生成する

7,
HTMLをブラウザに返す

gemfileとはバージョンを指定するファイル
Gemfileが変わったら必ずbundle install

間違っていたら申し訳ございません。

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?