A glossary of Rails terms for beginners.
The router is the component of Rails that takes your config/routes.rb
file,
reads your routes from it and uses them to respond to incoming requests.
If the requested URL is not defined in your routes, it will show a 404 page.
A route is a URL that your Web application responds to.
Examples might be /
for the home page and /pizza
for a pizza-related page.
Routes are defined in your config/routes.rb
file.
Each route you define needs to be associated to an HTTP verb, a controller and
an action.
The format for defining the controller and action is controller#action
.
For example:
get '/pizza' => 'food#pizza'
This route accepts GET requests to the /pizza
URL.
Such requests prompt Rails to call the pizza
action on FoodController
.
A controller is a class that is a collection of actions.
Actions are just methods on the controller.
A controller should group actions that are related.
For example you might make a FoodController
to group different actions related
to foods.
Controllers live in the app/controllers/
folder.
An action is a controller's method that handles a request on a route.
The kinds of requests that are handled by the action are defined in your
config/routes.rb
.
An action decides what code to run for that route and how to respond.