Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 routes to wrong controller

I wanted to create a new action and I call it "showemployees". That's what I did already:

-> in the controller:

def showemployees
end

-> creating app/views/employees/showemployees.html.erb

-> in config/routes

match "/employees/showemployees" => "employees#showemployees"

I thought this is enough for opening the showemployees.html.erb now via localhost:3000/employees/showemployees , but it seems like Rails still routes through the show action (from resources :employees) and doesn't take the showemployees-action, because it tells me

ActiveRecord::RecordNotFound in EmployeesController#show
Couldn't find Employee with ID=showemployees

What do I need to change so Rails takes the showemployees-action?


the source code of my route:

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
like image 700
Kirinriki Avatar asked Feb 23 '23 07:02

Kirinriki


1 Answers

try to walk by Rails-way, if you want to get collection, use the collection

resources :employees do
  collection do
    get :showemployees
  end
end
like image 150
Anatoly Avatar answered Feb 28 '23 02:02

Anatoly