-
Notifications
You must be signed in to change notification settings - Fork 43
Routing
Andrew Yaroshuk edited this page Jun 8, 2015
·
5 revisions
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
endNote, /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.
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"]
endAfter creating controllers you need to register them:
Base::App.routes.draw do |routes|
#routes describing here
register StoreController
register OtherController
endget(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)