【发布时间】:2011-11-24 12:39:56
【问题描述】:
我有一个简单的 Rails 应用程序,我试图在其中向数据库添加一种非常简单的记录类型(“client_types”)。
我在routes.rb 有一条路线,上面写着:
resources :client_types
据我了解,它应该是我的 client_types 资源的所有常规路由的代理。
所以当我浏览到以下 URL http://localhost:3000/client_types/new 时,我在运行时收到以下路由错误:
No route matches {:action=>"show", :controller=>"client_types"}
请注意这里有问题的操作是显示,而不是新的(我的控制器中有这两种方法)。
所以...我在上面的资源路线下方添加了以下路线,中提琴,它可以工作:
match 'client_types/new' => 'client_types#new', :as => :client_type
那么我错过了什么?我的假设是我的路由文件中的resources :client_types 会添加一条与我稍后明确添加的路由匹配的路由。
rake routes 揭示了以下内容:
client_types GET /client_types(.:format) {:action=>"index", :controller=>"client_types"}
POST /client_types(.:format) {:action=>"create", :controller=>"client_types"}
new_client_type GET /client_types/new(.:format) {:action=>"new", :controller=>"client_types"}
edit_client_type GET /client_types/:id/edit(.:format) {:action=>"edit", :controller=>"client_types"}
client_type GET /client_types/:id(.:format) {:action=>"show", :controller=>"client_types"}
PUT /client_types/:id(.:format) {:action=>"update", :controller=>"client_types"}
DELETE /client_types/:id(.:format) {:action=>"destroy", :controller=>"client_types"}
client_type /client_types/new(.:format) {:controller=>"client_types", :action=>"new"}
【问题讨论】:
-
请
rake routes报告您看到的内容 -
“当我着陆时” - 请描述您如何“着陆”,例如通过网址或链接?
-
“当我登陆时”是指浏览器中的网址。
-
请发布您的 routes.rb 文件内容
标签: ruby-on-rails ruby ruby-on-rails-3 url-routing rails-routing