Saturday, February 14, 2015

Mapping CRUD routes manually

So, in route.rb, adding this CRUD route:

resources: employees

Generates these routes:
$rake routes

         employees  GET       /employees(.:format)              employees#index
                            POST     /employees(.:format)              employees#create
  new_employee GET        /employees/new(.:format)      employees#new
   edit_employee GET        /employees/:id/edit(.:format) employees#edit
           employee GET        /employees/:id(.:format)        employees#show
                           PATCH   /employees/:id(.:format)        employees#update
                           PUT         /employees/:id(.:format)        employees#update

                           DELETE /employees/:id(.:format)        employees#destroy

To enter these manually, add:
get   'employees'              => 'employees#index'
post    'employees'              => 'employees#create'
get      'employees/new'      => 'employees#new',    as: :new_employee
get      'employees/:id/edit' => 'employees#edit',   as: :edit_employee
get      'employees/:id'        => 'employees#show',   as: :employee
patch  'employees/:id'        => 'employees#update'
put      'employees/:id'       => 'employees#update'
delete 'employees/:id'        => 'employees#destroy'

For more information see, http://guides.rubyonrails.org/routing.html