Search code examples
ruby-on-railsrubyactionsyntax-errorlink-to

Should this link_to code work? Ruby/Rails 4.0 and 2.0.0


I apologize if this is a poor question to ask, but I'm using Rails 4 and Ruby 2.0.0 to go through a tutorial that is taught in a slightly older version. I know I shouldn't do that... but I kinda am doing that anyway. :)

In the tutorial, he's teaching link_to to link between two different pages. Here is the code he gave us.

<p>
Time to say
<%= link_to "Goodbye!".:action =>"goodbye" %>
</p>


</body>

The "Goodbye!" is the link name, and "goodbye" is the filename. I could not get this code to work, and S.O helped me, but it does not agree with this dude's tutorial. my final code that worked was either of these:

<p>
Time to say
<%= link_to("Goodbye!", "goodbye") %>
</p>

and this:

say
<%= link_to "hello", "hello" %>
</p>
</body>

but the code the instructor gave me did not work, and I tried exchanging the . for a , and I tried leaving out the . and , altogether. neither worked. So my question is: Is the instructors code supposed to work? Maybe it is the ruby/rails version difference???


Solution

  • The '.' should be a ',' for sure.

    <%= link_to "Goodbye!", :action => "goodbye" %>
    

    should produce

    <a href="/controller/goodbye">Goodbye!</a>
    

    where 'controller' is the current controller.