eucalypt
Search…
Controllers
Controllers map the application to a specified base route. Each controller also contains routes that extend from the base route.

CLI tasks

Example

app/controllers/product_controller.rb
1
class ProductController < Eucalypt::Controller(route: '/products')
2
helpers ProductHelper if defined? ProductHelper
3
4
# Route: /products/
5
get '/' do
6
@products = Product.all
7
erb :'products/browse'
8
end
9
10
# Route: /products/:id
11
get '/:id' do |id|
12
@product = Product.find id
13
erb :'products/show'
14
end
15
end
Copied!
    The base route for the controller is specified in line 1:
    1
    ... < Eucalypt::Controller(route: '/products')
    Copied!
    Routes defined within this controller are relative to the base route (/products). This means that:
      get '/' maps to the route /products/
      get '/:id' maps to the route /products/:id

Main controller

The main controller (MainController) works slightly differently. Since it inherits directly from ApplicationController, you cannot specify a base route, as the controller is always mounted at /.
Last modified 2yr ago