4

我想创建一个新动作,我称之为“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
4

2 回答 2

5

尝试走 Rails-way,如果你想收集,使用收集

resources :employees do
  collection do
    get :showemployees
  end
end
于 2011-08-10T20:31:45.407 回答
3

如果您发布完整的路由文件,我们可以进行明确的调用,但根据错误消息,您似乎有更广泛的路由定义映射到在此路由上方定义的 employees#show 以使其匹配。

路由是按照定义的顺序进行评估的,所以如果你在窄路由之上定义了一个非常宽泛的路由模式,你的窄路由将永远不会被调用。

编辑:您需要将正斜杠从您的路线中取出并将 showemployees 添加到实际 URL,以便它读取

 match "employees/showemployees" => "employees#showemployees" 
于 2011-08-10T20:22:59.840 回答