Learning Ruby On Rails: Day 5

YIL (I couldn’t write a post yesterday because, well… I went to the Beyoncé concert. I learned stuff. I just couldn’t write about it… because Beyoncé).

But here’s the stuff I learned/did yesterday:

  • rails new demo to create a new project. I did this in a directory folder where I keep all my tutorials.
  • Navigated into demo and then typed bin/rails about and that told me all about the project I’d just made!
bin/rails about
  • Typed bin/rails server into the command line.
server running on localhost:3000

Then a review of MVC as it pertains to Rails:

  • Rails accepts incoming requests from the browser.
  • It decodes the request to find a controller.
  • It calls an action method in that controller.
  • The controller invokes a view to display the result to a user.

Next, I started making a “Hello World” app. For this app, I needed a controller a view and a route to connect them.

Why didn’t I need a model?

Because we have no data.

Cool. Got it. Let’s make the thingy.

In the command line I typed bin/rails generate controller Say hello goodbye. And check this out!

This command created a controller and the names of the actions we’ll take! rails generate logs files and directories and notes when it adds new Ruby files or directories to the application. So cool.

Then I got a bunch of feels because I started thinking about how many times I created these boiler plate chunks of code by hand in JavaScript. And then I thought about how the Rails approach works nicely with how my brain works. It forces me to think about what type of functionality I’ll want to have in my controller before simply making a controller file. So in one fell swoop, I’m conceptualizing the creation of the file and the function of the file itself. And I’m thankful for this.

Here’s what the controller looks like thus far:

lil cutie

K bye.

Next post, here.