Using a Custom Controller

This lesson will familiarize you with Rails actions and controllers.

At this point, we can see not only that we’ve connected the URL to our controller, but also that Rails is pointing the way to our next step. Namely, we have to tell Rails what to display. This is where views come in. Remember when we ran the script to create the new controller? That command added several files and a new directory to our application. That directory contains the template files for the controller’s views. In our case, we created a controller named say, so the views will be in the app/views/say directory.

By default, Rails looks for templates in a file with the same name as the action it’s handling. In our case, that means we need to replace a file called hello.html.erb in the app/views/say directory. We will explain why that is in a minute. For now, let’s put some basic HTML in there:

Get hands-on with 1200+ tech skills courses.