[RoR ] RoR網路應用程式開發與建置 第一章的範例
環境
ruby 1.8.6 (2008-03-03 patchlevel 114) [i386-linux]
Rails 2.0.2
各位好
我照著這本書的範例實作他第一章的內容 hello
過程如下:
$rails hello
$cd hello
$script/generate controller aisatsu dare hi bye
然後在app/models下建立檔案guest.rb
內容如下
class Guest
def initialize(name)
@name = name
end
attr_accessor :name
end
<EOF>
修改app/controllers/aisatsu_controller.rb改成以下內容
class AisatsuController < ApplicationController
def dare
end
def hi
@gueset = Guest.new(params[:guest][:name])
session[:guest] = @guest
end
def bye
@guest = session[:guest]
session[:guest] = nil
end
end
修改app/views/aisatsu/dare.html.erb
# 書上原本是寫dare.rhtml 但是我的project中只有 dare.html.erb
# 兩者是相同或可互通的嗎?
<% @title = 'enterance' %>
<h1> who are you? </h1>
<%= start_form_tag :action => :hi %>
<%= text_field :guest, :name %>
<%= submit_tag 'tell us '%>
<%= end_form_tag %>
修改app/views/aisatsu/hi.html.erb
<% @title = 'big door' %>
<h1><%= h "hello #{@guest.name} "%></h1>
<%= start_form_tag :action => :bye %>
<%= submit_tag 'go home'%>
<%= end_form_tag %>
修改app/views/aisatsu/bye.html.erb
<% @title = 'exit' %>
<h1><%= h "good bye #{@guest.name} ! "%></h1>
<%= start_form_tag :action => :dare %>
<%= submit_tag 'go back'%>
<%= end_form_tag %>
然後執行
$script/server
=> Booting WEBrick...
=> Rails application started on http://0.0.0.0:3000
=> Ctrl-C to shutdown server; call with --help for options
[2008-05-16 08:24:26] INFO WEBrick 1.3.1
[2008-05-16 08:24:26] INFO ruby 1.8.6 (2008-03-03) [i386-linux]
[2008-05-16 08:24:26] INFO WEBrick::HTTPServer#start: pid=7413 port=3000
連到http://0.0.0.0:3000/aisatsu/dare後顯示了
http://om.homelinux.org:3000/aisatsu/dare
上面顯示我app/views/aisatsu/dare.html.erb 的第3行有問題
但是我幾乎是照著書上打的 所以我不太了解問題出在哪
請各位指點一下 感謝
--
人家可不是為了你才這樣做的哦!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.223.229.207
※ 編輯: dendrobium 來自: 61.223.229.207 (05/16 08:55)
※ 編輯: dendrobium 來自: 61.223.229.207 (05/16 09:04)
推
05/16 10:17, , 1F
05/16 10:17, 1F
→
05/16 10:18, , 2F
05/16 10:18, 2F
→
05/16 12:04, , 3F
05/16 12:04, 3F
→
05/16 12:05, , 4F
05/16 12:05, 4F
→
05/16 12:18, , 5F
05/16 12:18, 5F
→
05/16 16:07, , 6F
05/16 16:07, 6F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 3 篇):
Ruby 近期熱門文章
PTT數位生活區 即時熱門文章