確認画面を作ってみた
http://kurobox.dnsalias.net/weblog/?p=29を見よう見まねで、確認画面を作ってみた。
お約束どおり、プロジェクトの作成
Welcome to the Rails Shell. This view is meant for advanced users and command line lovers as a text-based way
to run rails commands such as: rails, script/generate, script/plugin, gem, rake, etc.
This shell can replace the functionality of the Rake Tasks, Rails Plugins, and generators views.
>rails confirm_demo
exists
create app/controllers
create app/helpers
create app/models
【中略】
create log/server.log
create log/production.log
create log/development.log
create log/test.log
コントローラの作成
>cd confirm_demo
Switched current working project to confirm_demo
>ruby script/generate controller Disp
exists app/controllers/
exists app/helpers/
create app/views/disp
exists test/functional/
create test/unit/helpers/
create app/controllers/disp_controller.rb
create test/functional/disp_controller_test.rb
create app/helpers/disp_helper.rb
create test/unit/helpers/disp_helper_test.rbDispコントローラにはhelloRailsとconfirmの2つのアクションを作る。
- confirm_demo/app/controllers/disp_controller.rb
class DispController < ApplicationController def helloRails end def confirm @text1 = params[:member][:name] @text2 = params[:member][:addr] end end
入力画面のビューの作成
- confirm_demo/app/views/helloRails.html.erb
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>Railsによるフォームサンプル</title> </head> <body> <h1> お問い合わせフォームサンプル </h1> <% form_for :member, :url => {:controller => 'disp',:action => 'confirm' } do |f| %> 名前:<%= f.text_field :name %><br/> 住所:<%= f.text_field :addr %><br/> <br/> <%= f.submit '送信' %> <%end%> </body> </html>
確認画面のビューの作成
- confirm_demo/app/views/confirm.html.erb
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Railsによるフォームサンプル</title> </head> <body> <h1> お問い合わせフォームサンプル </h1> <br/> 入力した名前:<%= h @text1 %><br/> 入力した住所:<%= h @text2 %><br/> <br/> <%= link_to '戻る', :controller => 'disp', :action => 'helloRails' %> </body> </html>
#h()を付けてサニタイズ対策してみた。