railsやってみた
以下を参考にしてやってみた。www.rubylife.jp
作成
rails new Sample
静的コンテンツ
public以下にhtmlをおく。
コントローラ
rails generate controller poge
作られたpoge_controllerにアクションを設置
class PogeController < ApplicationController def hello render :text => 'hello...' end end
ルーティングを設定(config/routes.rb)
get 'poge/hello' => 'poge#hello'
WeBrickたちあげて
ブラウザで確認
http://localhost:3000/poge/hello
Viewをつける
app/views/pogeに入り
テンプレート作成
touch hello.html.erb
<h1>hello...</h1> <p> hello..... </p>
コントローラをビューを参照するようにする。
class PogeController < ApplicationController def hello render "poge/hello" end end
WeBrickたちあげてブラウザで確認
http://localhost:3000/poge/hello
テンプレートいじる
<h1>hello...</h1> <p> hello..... <%= @msg %> </p>
として、コントローラ側で@msgに代入
class PogeController < ApplicationController def hello @msg = 'orz'; render "poge/hello" end end
WeBrickたちあげてブラウザで確認
http://localhost:3000/poge/hello