最初の一歩
Hello Rails! と表示するアプリケーションを作成してみます。
> rails new hello
> cd hello
> rails server
WEBrick(HTTP)サーバーが起動すると以下のようなメッセージが表示されます。
=> Booting WEBrick
=> Rails 3.0.7 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-06-28 14:53:54] INFO WEBrick 1.3.1
[2011-06-28 14:53:54] INFO ruby 1.8.7 (2011-02-18) [i386-netbsdelf]
[2011-06-28 14:53:54] INFO WEBrick::HTTPServer#start: pid=8296 port=3000
サーバーが起動したらポート3000を指定して接続します。
例)
http://192.168.1.10:3000
コントローラー作成
index というアクションのある main コントローラーを作成します。
> rails generate controller main index
> rails server
ブラウザで確認します。
例)
http:192.168.1.10:3000/main/index
Hello Rails!
ブラウザにHello Rails!と表示させるよう修正します。
app/views/main/index.html.erb
<h1>Main#index</h1>
<p>Find me in app/views/main/index.html.erb</p>
<p>Hello Rails!</p>
ブラウザで確認します。
例)
http:192.168.1.10:3000/main/index