我不知道为什么我的应用程序不响应任何POST请求,这是一个非rest url。
下面是我的路线。rb文件。
constraints(Subdomain) do
resources :invitations
resources :settings, :only => [:index, :create, :destroy]
scope "/settings" do
get "/departments" => "settings#departments"
get "/job_types" => "settings#job_types"
get "/industries" => "settings#industries"
get "/functional_areas" => "settings#functional_areas"
get "/managers" => "settings#managers"
get "/hrs_responsible" => "settings#hrs_responsible"
get "/welcome_text" => "settings#welcome_text"
post "/save_welcome_text" => "settings#save_welcome_text" <-------
end
end
在视图文件中,我有
=form_for(@setting), :url => "/settings/save_welcome_text", :method => :post do |f|
- All the form fields here.
- f.submit "Save"
此要点包含生成的HTML和相应的服务器日志。https://gist.github.com/943984
当我点击提交时,我看到"路由错误",没有这样的路由存在。从服务器日志中,我可以嗅出请求是作为POST请求发送的。但是,如果我将它从路由中的"post"改为"match"。Rb文件,这工作。所有GET请求都可以正常工作。我错过什么了吗?
您应该在html
块中指定method
=form_for(@setting), :url => "/settings/save_welcome_text", :html => { :method => :post } do |f|
get和post方法在路由中的使用。根据我的理解,rb只对资源块中的成员或集合路由可用。
如果你不这样做,你必须使用match,如果你只想让它在post中可用,那么你可以这样指定:
match "/save_welcome_text" => "settings#save_welcome_text", :via => :post