Controllers
Overview
Suppose we wanted to add routes to our Padrino application, and we want to
organize a set of related routes within a more structured grouping. Padrino has
the notion of a 'controller' block which can group related routes and make URL
generation much easier. Simply add a controllers.rb
file or app/controllers
folder and create a file as such:
# app/controllers/main.rb or controllers.rb
SimpleApp.controller do
get "/test" do
"Text to return"
end
get "/sample" do
"Sample Route"
end
end
In this case, the controller merely acts as a structured grouping mechanism to allow better organization of routes. Controllers actually have other benefits as well when used in conjunction with the enhanced Padrino routing system.
- Routing
- Layouts
- Provides Formats
- Route Filters
- Prioritized Routes
- Custom Conditions
- Parsing Params
- Rendering
- Sessions
- Params Whitelisting
last updated: 2022-02-22
comments powered by Disqus