【发布时间】:2012-02-18 02:47:46
【问题描述】:
这是我的控制器:
class TalentController < ApplicationController
def index
end
def new
@talent = Talent.new
end
def create
@talent.update_attributes!(params)
end
end
这是我的 app/views/talent/new.html.haml:
= "Create new talent"
= form_for @talent, :url => {:action=>:create, :controller=>"talent"}, :method => :post do |f|
= f.label :First_Name
= f.text_field :first_name
= f.label :Last_Name
= f.text_field :last_name
= f.label :City
= f.text_field :city
= f.label :State
= f.text_field :state
= f.label :Zip_code
= f.text_field :zip_code
= f.submit "Create"
当我点击创建按钮时,我得到了这个错误。
No route matches [POST] "/talent/new"
这是我的 rake 路线:
/ {:action=>"index", :controller=>"talent"}
talent_index GET /talent(.:format) {:action=>"index", :controller=>"talent"}
POST /talent(.:format) {:action=>"create", :controller=>"talent"}
new_talent GET /talent/new(.:format) {:action=>"new", :controller=>"talent"}
edit_talent GET /talent/:id/edit(.:format) {:action=>"edit", :controller=>"talent"}
talent GET /talent/:id(.:format) {:action=>"show", :controller=>"talent"}
PUT /talent/:id(.:format) {:action=>"update", :controller=>"talent"}
DELETE /talent/:id(.:format) {:action=>"destroy", :controller=>"talent"}
我在这里错过了什么??
【问题讨论】:
-
尽量不要为表单指定
:url和:method。只需= form_for @talent。 -
另外,在您的
create操作中,您会遇到异常,因为未定义@talent。
标签: ruby-on-rails ruby-on-rails-3 forms post haml