Image for post
Image for post
“Helo wirld I am smol”

Learning Ruby On Rails: Day 6

Morgan Fogarty
Oct 11, 2018 · 3 min read

Today, I learned about adding dynamic data to my “Hello World” app.

A Rails app, like any other web app, is associated with a URL. When someone points to the URL, they’re communicating with the application code.

Kewl.

I navigated to http://localhost:3000/say/hello and I saw the following:

Image for post
Image for post

Telling me where I can adjust its view! The view file was created when we created the controller earlier. So neat.

Then I made the app say a thing by navigating to the file and adding simple HTML:

When I refreshed the browser this happened:

Image for post
Image for post

Then, I added the time (the dynamic data) directly to the HTML.

Code that’s written between is interpreted as Ruby code and executed. So, I did the following:

Image for post
Image for post

And the time plopped out onto the screen.

Image for post
Image for post

This worked, but I should really keep logic in the controller. I don’t want to make a big mess in the view if I end up building out the app. So, I moved the logic to the controller and saved to a variable.

Image for post
Image for post

And, then reference that variable from the view.

Image for post
Image for post

And, it still worked!

Other stuff I learned:

  • means Embedded Ruby or Ruby that is embedded into text/view files. It reminds me of JSX in React.
  • When we add code in development mode, we don’t have to restart the server. Rails dispatcher automatically reloads application source files when a new request comes along. This is like Nodemon in Node Land. In both cases, this feature should not be used in production.

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