Helloアプリケーションの開発

p.2から7まで。
ここまでの作業はbitbucketにpushした。
http://bitbucket.org/shokai/web-innovative/changeset/4fbcc1acc524/



授業で使うrailsが2.0.2なのでバージョン指定して使う

rails _2.0.2_ hello

とすると2.0.2が使える。


プロジェクト新しく作ってwebrick起動

rails _2.0.2_ hello
cd hello
ruby script/server

http://localhost:3000/ で起動しているので確認

ruby script/generate controller main index

app/controller/main_controller.rb を編集

lass MainController < ApplicationController

  def index
    @message = "HELLO, ruby on rails via ruby"
    @time = Time.now # 現在時刻
  end
end


app/view/main/index.html.erb

<%= @message %></h1>
現在時刻: <%= @time %>

で、 http://localhost:3000/main/index にアクセスするとcontrollerが指定した現在時刻とメッセージが表示されている。
index

URLのmain/indexは、controller名/メソッド名というルーティングを表している。