Skip to content
Andrew Yaroshuk edited this page Jun 8, 2015 · 5 revisions

Routing

Amethyst has Rails-like approach to describe routes:

Base::App.routes.draw do |routes|
  # maps GET "/" to "hello" action of IndexController
  get "/",    "index#hello"
  # maps GET, POST, PUT, DELETE "/bye" to "bye" action of IndexController
  all "/bye", "index#bye"
  # maps POST "/form/ to "form" action of IndexController
  post "/form/", "index#form" 
  
  register IndexController # registering controller in router
end

Note, /bye and /bye/ work slightly different. First matches /bye, /bye/, /bye_something, second is "strict", and matches only /bye and /bye/. Both not matches /bye/something. See how describe routes in application class.

Path params

You can specify params to be captured:

get "/users/:id", "users#show"

This parameter will be available at UsersController show action:

def show
   request.path_params["id"]
end

Controllers registering

After creating controllers you need to register them:

Base::App.routes.draw do |routes|
  #routes describing here
  register StoreController
  register OtherController
end

Currently, following route "drawers" available:

  • get(pattern : String, controller_action : String)
  • post(pattern : String, controller_action : String)
  • put(pattern : String, controller_action : String)
  • delete(pattern : String, controller_action : String)
  • all(pattern : String, controller_action : String)
Clone this wiki locally