【发布时间】:2011-08-10 20:19:31
【问题描述】:
我想创建一个新动作,我称之为“showemployees”。这就是我已经做过的:
-> 在控制器中:
def showemployees
end
-> 创建 app/views/employees/showemployees.html.erb
-> 在配置/路由中
match "/employees/showemployees" => "employees#showemployees"
我认为现在通过 localhost:3000/employees/showemployees 打开 showemployees.html.erb 就足够了,但似乎 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
【问题讨论】:
-
您是否尝试将
match语句放在resources语句之前在您的routes.rb中?在某些情况下,顺序很重要。 -
是的,我已经把
match放在每条语句之前,因为它在路由文件的cmets中写了顺序很重要,但它不起作用。 :( -
那么,您实际拥有哪条路线?
match "/employees"还是match "/employees/showemployees"?您的示例与您所说的不符。 -
我建议您将操作重命名为 show_multiple、update_multiple,如果您有任何依赖项,请使用嵌套路由
-
这对我来说“有味道”。
showemployees动作做了什么而index动作不会?我同意米哈伊洛夫的观点
标签: ruby-on-rails ruby-on-rails-3 rails-routing