rails console, let's get a sneak peek at how this is going to let us build dynamic web apps!
rails console, only to have them forever lost if you close Terminal. So let's write them down permanently into a source code file, just like you did with your HTML.
https://ide.c9.io/YOUR_USERNAME/ruby-intro(or whatever you named your workspace) — click the "Run Project" button at the top of the IDE if not.
app/controllers/programs_controller.rband double-click it:
"Replace this string with your output"to any Ruby expression that you want.
6 * 7or any other Ruby expression that you just learned in the previous chapters, but to make it very clear that it's dynamic, try something random —
["heads", "tails"].sample— and then refresh your app in the other Chrome tab. Refresh again a couple of times. You should see dynamic content!
# Your code goes hereand
render("programs/home.html.erb"), and assign the final value that you'd like to appear on the page to the special variable
@your_output. (Variables whose names begin with the letter
@are called instance variables, and are the ones we intend to display to our users. You can create and use them just like any other variables.)
app/views/programs/home.html.erb, which should currently look something like this:
<%= @your_output %>alone, though; just move it around or wrap it within new HTML if you want to.
programs_controller.rband use them in your view template, if you like: