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 (http://localhost:3000/say/hello).
  • Rails matches the route pattern which it split into two parts (on slashes) and analyzed.
  • The say part of the URL is taken as the controller name and Rails creates an instance of the SayController class.
  • The hello part of the URL identifies an action. Rails invokes the method of that name in the controller.
  • The hello method creates a new Time object and saves it in the @time instance variable.
  • Rails looks for a template to display the result. It searches in the app/views directory for a subdirectory with the same name as the controller.
  • Once it finds the app/views/say subdirectory, Rails looks for a file named after the action. In this case, hello.html.erb.
  • 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:

say meow

and my computer will say “meow”.

Next post, here.