Routing
The router maps screen paths like /users/42 to a controller action. You declare routes once with a small DSL (usually in config/routes.rb), and the runtime resolves every navigation through them — there is no other way to reach a screen. For the broader picture of how routes, controllers, and views fit together, see Routing.
Defining routes
Routes are usually defined in config/routes.rb:
MyApp::Application.routes do
root "home#show"
screen "/users/:id", to: "users#show", title: "User"
end
DSL methods:
root "controller#action", title: "Home"maps/.screen "/path", to: "controller#action", title: nilmaps a screen path.- Omitting
#actioninto:defaults the action to#show.
Resolution rules
- Exact routes win over dynamic routes.
- Dynamic segments use
:nameand match one segment. - Params are symbol-keyed, for example
params[:id]. - Params are URL-decoded.
- Missing routes raise
KeyError.
So navigating to /users/42 with the routes above dispatches UsersController#show with params[:id] == "42".
Route objects
Route objects expose:
pathcontroller_classactiontitleparams