gpt4 book ai didi

ruby-on-rails - Rails 3 路由到错误的 Controller

转载 作者:行者123 更新时间:2023-12-03 00:31:30 26 4
gpt4 key购买 nike

我想创建一个新操作,我将其称为“showemployees”。这就是我已经做过的:

-> 在 Controller 中:

def showemployees
end

-> 创建 app/views/employees/showemployees.html.erb

-> 在配置/路由中

匹配“/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

最佳答案

尝试走Rails方式,如果你想得到集合,就使用集合

resources :employees do
collection do
get :showemployees
end
end

关于ruby-on-rails - Rails 3 路由到错误的 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7017231/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com