在校生大三生,一直做JEE的项目,由于对Ruby的兴趣,买了本<<Rails CookBook>>,按照例子想做个Demo,刚接触由于不太熟悉,在NetBeans中开发,服务启动后:在http://localhost:3000/WebList
出错:
Routing Error
No route matches "/WebList" with {:method=>:get}
以下是目录与代码:(项目名为WebList)
~WebList/app/models/people.rb
--------------------------------
class People<ActiveRecord::Base
end
--------------------------------
~WebList/app/views/index.rhtml
--------------------------------
<p style="color:green"><%=flash[:notice]%></p>
<h1> 建立People</h1>
<form action="create" method="post">
<p>Name:
<%=text_field "people","name","size"=>20%></p>
<p>Email:
<%=text_field "people","email","size"=>20%></p>
<p>Phone:
<%=text_field "people","phone","size"=>20%></p>
<input type="submit" value="Save">
</form>
---------------------------------
WebList/app/controllers/people_controllers.rb
----------------------------------
def create
@people=People.new(params[:people])
if @people.save
flash[:notice]="Ok,it's will be created! :)"
redirect_to:action =>'list'
else
flash[:notice]="失败了"
render:action =>'new'
end
end
--------------------------------------
WebList/db/schema.rb
----------------------------------------
ActiveRecord::Schema.define(:version => 1) do
create_table "people",force => true do |t|
t.column "name",:string
t.column "email",string
t.column "phone",string
end
end
-----------------------------------------
一切 ok,就是往数据库里写三个字段,可是问题来了,在config中不知道怎么配置这个路由,希望大家帮帮我,谢谢!~
出错:
Routing Error
No route matches "/WebList" with {:method=>:get}
以下是目录与代码:(项目名为WebList)
~WebList/app/models/people.rb
--------------------------------
class People<ActiveRecord::Base
end
--------------------------------
~WebList/app/views/index.rhtml
--------------------------------
<p style="color:green"><%=flash[:notice]%></p>
<h1> 建立People</h1>
<form action="create" method="post">
<p>Name:
<%=text_field "people","name","size"=>20%></p>
<p>Email:
<%=text_field "people","email","size"=>20%></p>
<p>Phone:
<%=text_field "people","phone","size"=>20%></p>
<input type="submit" value="Save">
</form>
---------------------------------
WebList/app/controllers/people_controllers.rb
----------------------------------
def create
@people=People.new(params[:people])
if @people.save
flash[:notice]="Ok,it's will be created! :)"
redirect_to:action =>'list'
else
flash[:notice]="失败了"
render:action =>'new'
end
end
--------------------------------------
WebList/db/schema.rb
----------------------------------------
ActiveRecord::Schema.define(:version => 1) do
create_table "people",force => true do |t|
t.column "name",:string
t.column "email",string
t.column "phone",string
end
end
-----------------------------------------
一切 ok,就是往数据库里写三个字段,可是问题来了,在config中不知道怎么配置这个路由,希望大家帮帮我,谢谢!~