Learning Ruby On Rails: Day 7
Today was review day. This is all pertaining to my tiny “Hello World” app.
Here’s how it werks:
- The user (in this case, me) navigates to a URL (
- Rails matches the route pattern which it split into two parts (on slashes) and analyzed.
saypart of the URL is taken as the controller name and Rails creates an instance of the
hellopart of the URL identifies an action. Rails invokes the method of that name in the controller.
hellomethod creates a new
Timeobject and saves it in the
- Rails looks for a template to display the result. It searches in the
app/viewsdirectory for a subdirectory with the same name as the controller.
- Once it finds the
app/views/saysubdirectory, Rails looks for a file named after the action. In this case,
- Rails processes this file through ERB, executing any embedded Ruby and substituting values set up by the controller.
- Rails finishes processing the request and the result is returned to the browser.
These steps illustrate Convention Over Configuration, the Rails philosophy that I keep hearing so much about. I love it! It’s like Rails knows what we want to do before we know. ❤
Separate, but as important, TIL that I can type into the command line:
and my computer will say “meow”.
Next post, here.