23
17

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 g scaffoldとは?

Posted at

#はじめに。
学びをアウトプットしたかったので、scaffoldについて簡単にまとめてみました。

##scaffoldってなに?
railsでは、rails gコマンドでコントローラーやモデルを作成し、ルーティングでページを繋げる操作が必要。
Webアプリケーションに必要なこれらの操作を一度に自動で組み立ててくれるのがscaffold。
scaffoldの本来の意味は足場です。足場を作ってその上に自分の作りたいものを組み上げていくイメージ。

##scaffoldの使い方
例としてhoge_appを作るとすると
$ rails new hoge_app
hoge_app内に入る。
$ cd /hoge_app
アプリ内で、scaffoldを使う。
$ rails g scaffold hoge title:string content:text
このコマンドだけでhogesコントローラーやhogeモデルができる。

マイグレーション後にサーバを立ち上げましょう。
$ rake db:migrate
$ rails s

ブラウザよりlocalhost:3000/hogesにアクセスするとtitleとcontentに入力ができ、保存が可能になる。上記の手順を踏むだけで、簡単なアプリが完成してしまうのがRailsだと感じた。しかし、個人的に、はじめのうちはMVCやルーティングについての理解がまだ浅いと思うからscaffoldではなく、model,controllerなど細かく作成していくほうが理解を深めるのにはいいのかなと思った。

23
17
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
23
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?