尝试使用show的新动作

时间:2011-06-26 05:13:26

标签: ruby-on-rails-3 routes ruby-on-rails-3.1

以下是我的路线:

equipment_index GET    /equipment(.:format)           {:action=>"index", :controller=>"equipment"}
            POST   /equipment(.:format)           {:action=>"create", :controller=>"equipment"}
new_equipment GET    /equipment/new(.:format)       {:action=>"new", :controller=>"equipment"}
edit_equipment GET    /equipment/:id/edit(.:format)  {:action=>"edit", :controller=>"equipment"}
equipment GET    /equipment/:id(.:format)       {:action=>"show", :controller=>"equipment"}
            PUT    /equipment/:id(.:format)       {:action=>"update", :controller=>"equipment"}
            DELETE /equipment/:id(.:format)       {:action=>"destroy", :controller=>"equipment"}
categories GET    /categories(.:format)          {:action=>"index", :controller=>"categories"}
            POST   /categories(.:format)          {:action=>"create", :controller=>"categories"}
new_category GET    /categories/new(.:format)      {:action=>"new", :controller=>"categories"}
edit_category GET    /categories/:id/edit(.:format) {:action=>"edit", :controller=>"categories"}
category GET    /categories/:id(.:format)      {:action=>"show", :controller=>"categories"}
            PUT    /categories/:id(.:format)      {:action=>"update", :controller=>"categories"}
            DELETE /categories/:id(.:format)      {:action=>"destroy", :controller=>"categories"}

当我转到http://localhost:3000/equipment/new时,我收到以下错误:

No route matches {:action=>"show", :controller=>"equipment"}

这是我的routes.rb文件:

Equipmentmanager::Application.routes.draw do
  resources :equipment
  resources :categories
end

其他所有内容都设置为默认值,除了我使用的是nifty:scaffold。

这是在3.1中,但它也在3.0中完成 我不确定我错过了什么?

1 个答案:

答案 0 :(得分:0)

所以localhost:3000 / equipment / new正在使用此行路由:

equipment GET /equipment/:id(.:format) {:action=>"show", :controller=>"equipment"}

应该如此。由于您希望它实际转到新路由,因此您需要调用localhost:3000 / new_equipment,因为您已定义该路由。

如果您希望localhost:3000 / new_equipment路由到新操作,请将此行放在您的routes.rb文件中(在资源:设备行之上,因为它更具体),作为一个更清晰的语法:

get "new_equipment" => "equipment#new", :as => "new_equipment"

该行还将定义帮助您访问new_equipment_path和new_equipment_url

的帮助程序