Learning Ruby On Rails: Day 8
I have this tiny “Hello world” app.
It has one page.
Now I will give it another page.
Each page will correspond with a separate view
. For this new page I will use a new action method (goodbye
) which will be in the same controller I’ve been working with(say_controller.rb
).
New action method. Same controller. Here we go.
I add html
to goodbye.html.erb
so that it will show “Goodbye”. That’s fine but I’d really like to add links between both pages, too.
For links I will use a helper method!
link_to()
creates a hyperlink to an action.
So in my hello.html.erb
I add a link to the goodbye
view. The code looks like this:
On line 7, "Goodbye"
is the text of the hyperlink. say_goodbye_path
is the precomputed value that Rails makes available to application views. It evaluates to say/goodbye
path.
And the page looks like this:
Now I will add a link from the “Goodbye” page to the “Hello” page.
It looks like this:
Also most importantly TIL that if I type cowsay meow
into my terminal I will get an emoticon cow saying “meow”. It looks like this:
And I had to run brew install cowsay
in order to have this ability. I regret nothing.
Next post, here.