Learning Ruby On Rails: Day 9

Morgan Fogarty
Oct 16, 2018 · 3 min read

The tiny “Hello World” app has two pages that link to each other. It works!

Now to break it so I can see why it works.

First I added a typo in the code:

Image for post
Image for post

I changed Time.now()(a Ruby method on a Time object) to Time.know()(a nonsense method on a Time object).

In the browser, the following appeared

Image for post
Image for post

Then I tried messing with the URL and in the browser. A Routing Error appeared:

Image for post
Image for post

These error messages are so helpful and clear. The Routing Error message even has an input field where you can search for the correct path:

Image for post
Image for post

What a dream.

So in my first few days of learning Ruby on Rails, I’ve done the following:

  • created a tiny app
  • created a tiny controller, at which time, Rails created a view template for each of the methods inside the tiny controller
  • linked the views together
  • practiced debugging problems in the code and in the URL

It’s been real.

I have a couple Q’s though:

  1. Can I create new methods in the controller in my text editor or do I have to do it via the terminal? I’m pretty sure I know the answer to this, but I like to ask all the questions.
  2. Why doesn’t the following code execute when I put it in the controller?

@addition = <%= 1 + 3 %>

Answer to Question 1: I can create new controller methods in the text editor! But then the view templates aren’t auto-created by Rails.

When I first created the controller, I typed rails generate controller Say hello goodbye and the views for hello and goodbye were simultaneously created. If I run that command again with a new method name, I get a conflict error:

Image for post
Image for post

So I’ll add them via the text editor and then I’ll be sure to add the corresponding views.

Answer to Question 2: Because it’s erb! That’s gotta go in the html.erb file, kid.

Next post, here.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store