Question

I wanted to know what the easiest way to rename a restful route is. Basically I have a controller called Employees and rather than have employees/new I want employees/hire to be used and achieve the same thing and make employees/new an invalid url.

Was it helpful?

Solution

For your specific need, the guide has exactly this example for new, edit, this should work:

resources :employees, :path_names => { :new => 'hire' }

http://guides.rubyonrails.org/routing.html#overriding-the-new-and-edit-segments

OTHER TIPS

One of the best sources of data on routes is the rails guide: Rails Guide on Routes, also the command

rake routes

This command will show you all the current routes.

But in answer to this specification question if you look into your routes file you can create new routes manually.

match 'employee/hire' => 'Employees#new', :via => :get, :as => 'employee_path'

the first argument matches what the browser is looking for. The second argument is the controller and method. The third is if it is a get, put, post, or delete call. The fourth is the name for the path so you can access with the standard name_path type of call from code.

This makes sense?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top