parm530
4/4/2018 - 3:42 PM

Routing

How to create routes

Routing

  • simple route (also known as match)
    • get "demo/index"
    • same as the longer version: match "demo/index", :to => "demo#index", :via => :get
  • default route
    • Difference from above is that a simple route is explicit, it needs controller and action otherwise it'll give an error
    • With the default route, the action doesn't need to be provided, the route will go to the controller
    • format controller/action/id
    • Ex: GET '/students/edit/52' -> StudentsController, edit action, student with id = 52
    • match ':controller(/:action(/:id))', :via => :get
  • root route
    • when no route is provided: root :to => "demo#index" or root "demo#index"