[英]Rails 3 routes to wrong controller
我想创建一个新动作,我称之为“showemployees”。 这就是我已经做的:
-> 在 controller 中:
def showemployees
end
-> 创建应用程序/视图/员工/showemployees.html.erb
-> 在配置/路由中
match "/employees/showemployees" => "employees#showemployees"
我认为这足以打开 showemployees.html.erb 现在通过localhost:3000/employees/showemployees ,但似乎 Rails 仍然通过 show 操作(来自资源:employees)并且不采取 showemployees-action,因为它告诉我
ActiveRecord::RecordNotFound in EmployeesController#show
Couldn't find Employee with ID=showemployees
我需要更改什么才能让 Rails 采取 showemployees-action?
我的路线的源代码:
System::Application.routes.draw do
match "/employees/showemployees" => "employees#showemployees" #für showemployees.html.erb
root :to => "employees#index"
resources :course_to_dos
resources :current_qualifications
resources :expected_qualifications
resources :skills
resources :employees
resources :positions
resources :admin
end
尝试走 Rails-way,如果你想收集,使用收集
resources :employees do
collection do
get :showemployees
end
end
如果您发布完整的路由文件,我们可以进行明确的调用,但根据错误消息,看起来您有更广泛的路由定义映射到在此路由上方定义的 employees#show 以使其匹配的方式。
路由是按照定义的顺序进行评估的,所以如果你在窄路由之上定义了一个非常宽泛的路由模式,你的窄路由将永远不会被调用。
编辑:您需要将正斜杠从您的路线中删除,并将 showemployees 添加到实际的 URL 中,以便它读取
match "employees/showemployees" => "employees#showemployees"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.