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
endAll lessons in this course
- Routes and Resources
- Controllers and Actions
- Strong Parameters
- Views and Rendering