我不确定我做错了什么。我有一个项目资源:
resources :projects
在 ProjectsController#new 中,我正在创建一个项目并将其呈现在 new.html.erb 中:
<%= form_for @project do |f| %>
<%= f.label :name %>
<%= f.text_field :name%><br/>
<%= f.submit %>
<% end %>
这会被 POST,但不是由 Projects#create 处理,而是由 home 操作处理:
Started POST "/projects" for 127.0.0.1 at 2012-11-02 08:47:36 -0500
Processing by ProjectsController#home as HTML
这是我的路线:
/ projects#home
projects /projects(.:format) projects#home
GET /projects(.:format) projects#index
POST /projects(.:format) projects#create
new_project GET /projects/new(.:format) projects#new
edit_project GET /projects/:id/edit(.:format) projects#edit
project GET /projects/:id(.:format) projects#show
PUT /projects/:id(.:format) projects#update
DELETE /projects/:id(.:format) projects#destroy
编辑:我发现了问题。
这是旧的路线文件:
SolarMesh::Application.routes.draw do
match '/' => 'projects#home'
match '/projects' => 'projects#home'
resources :projects
end
“匹配'/项目'”这行是它总是由家庭处理的原因。