0Pricing
Ruby Academy · Lesson

Controllers and Actions

Handling requests.

What Is a Controller?

A controller receives a request from the router, does the work, and decides what to send back. It is the coordinator between models and views.

  • Controllers live in app/controllers.
  • They inherit from ApplicationController.
  • Each public method is an action.

Defining a Controller

A controller is a class ending in Controller. By convention ArticlesController handles routes for the articles resource.

class ArticlesController < ApplicationController
  def index
    @articles = Article.all
  end
end

All lessons in this course

  1. Routes and Resources
  2. Controllers and Actions
  3. Strong Parameters
  4. Views and Rendering
← Back to Ruby Academy