eucalypt
>= 0.9.0
>= 0.9.0
  • eucalypt
  • Installation
  • CLI
    • Core
      • Init
      • Launch
      • Console
      • Test
      • Version
      • Rake
      • Help (-H)
    • Generate
      • Controller
      • Helper
      • Model
      • Scaffold
    • Destroy
      • Controller
      • Helper
      • Model
      • Scaffold
    • Blog
      • Setup
      • Article
        • List
        • Generate
        • Destroy
        • Edit
          • Urltitle
          • Datetime
    • Migration
      • Blank
      • Types
      • Create
        • Table
      • Add
        • Index
        • Column
      • Drop
        • Table
        • Index
        • Column
      • Rename
        • Table
        • Index
        • Column
      • Change
        • Column
  • Features
    • Controllers
    • Helpers
    • Views
      • Layouts
      • Partials
    • Static data
    • Core application file
    • Configuration
      • Logging
      • Asset pipeline
        • Manifest asset files
      • Initializers
      • Database
    • Manifest accessor
    • Application path helpers
    • Blog environment
      • Articles
    • Rendering static files
    • Maintenance mode
Powered by GitBook
On this page
  • CLI tasks
  • Example
  • Main controller
  1. Features

Controllers

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

PreviousFeaturesNextHelpers

Last updated 6 years ago

CLI tasks

Example

app/controllers/product_controller.rb

class ProductController < Eucalypt::Controller(route: '/products')
  helpers ProductHelper if defined? ProductHelper
  
  # Route: /products/
  get '/' do
    @products = Product.all
    erb :'products/browse'
  end
  
  # Route: /products/:id
  get '/:id' do |id|
    @product = Product.find id
    erb :'products/show'
  end
end
  • The base route for the controller is specified in line 1:

    ... < Eucalypt::Controller(route: '/products')
  • 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 /.

Generate
Destroy