scaffoldジェネレータの実行

広告
facebookボタン
googleplusボタン
twitterボタン
ダミーボタン
bloggerボタン

それではscaffoldジェネレータを実行します。「script」ディレクトリの中に作成されている「generate」スクリプトを使用して次のように作成します。

ruby script¥generate scaffold モデル名 カラム名:型 カラム名:型 ...

最初の引数に「scaffold」を指定し、続いてモデル名を指定します。その後でテーブルに作成するカラムに関する情報を「カラム名:データ型」の形式で指定して下さい。複数のカラムを使用する場合は空白で区切って続けて指定します。

今回はモデル名として「infomation」、そしてカラムとして「id:integer」「name:string」の二つを指定します。(データ型として指定可能な値は別のページで解説します)。

ruby script¥generate scaffold infomation id:integer name:string

p3-1

では実行します。

p3-2

複数のディレクトリ及びファイルが作成されます。ファイルの一覧だけ取得すると次の通りです。

app/views/infomations/index.html.erb
app/views/infomations/show.html.erb
app/views/infomations/new.html.erb
app/views/infomations/edit.html.erb
app/views/layouts/infomations.html.erb
public/stylesheets/scaffold.css
app/controllers/infomations_controller.rb
test/functional/infomations_controller_test.rb
app/helpers/infomations_helper.rb
test/unit/helpers/infomations_helper_test.rb
app/models/infomation.rb
test/unit/infomation_test.rb
test/fixtures/infomations.yml
db/migrate/20100509135043_create_infomations.rb

ビュー、コントローラー、モデル、マイグレーション定義ファイルなどが作成されています。各ファイルについては別のページで内容を確認します。

( Written by T.buzz.Ikura+ )

Social Button
Facebook Page