本文介绍了尝试使用表演的新动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的路线:

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"}

当我转到时,我得到了以下错误:

When I go to http://localhost:3000/equipment/new I get the following error:

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

这是我的route.rb文件:

This is my routes.rb file:

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

除我使用nifty:scaffold之外,其他所有设置都设置为默认值。

Everything else are set to the defaults, except that I used nifty:scaffold.

这是3.1版本,但在3.0版本中也可以做到
我不确定我缺少什么吗?

This is in 3.1, but it does it in 3.0 alsoI am not sure what I am missing?

推荐答案

因此,localhost:3000 / equipment / new正在通过以下行进行路由:

So localhost:3000/equipment/new is getting routed with this line:

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

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

As it should be. Since you want it to actually go to the new route you need to call localhost:3000/new_equipment since you have defined that route.

作为一种更简洁的语法,如果您希望将localhost:3000 / new_equipment路由到新操作,则可以将此行放入route.rb文件中(在资源上方:设备行,因为它更具体):

As a bit cleaner syntax if you wanted localhost:3000/new_equipment to route to the new action you could put this line in your routes.rb file (above the resources :equipment line since its more specific):

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

该行还将定义帮助程序,使您可以访问new_equipment_path和new_equipment_url

That line will also define helpers that give you access to new_equipment_path and new_equipment_url

这篇关于尝试使用表演的新动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 03:31