Domanda

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???

È stato utile?

Soluzione

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.

Altri suggerimenti

The . is a typo on someone's part. It should definitely be ,, because it's separating two arguments to the method invocation. Also, the second argument is specifying the method, which indirectly implies a filename. See http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to for documentation and if you want more help, please share the specific error you can when you replace the . with a ,.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top