Link_to image_tag external url

I am a recent rails convert

Is it possible to link to an external site using the link_to image_tag

this is the code I have

<%= link_to image_tag ("Twitter.png"), https://twitter.com/ %>

On Sun, Aug 11, 2013 at 8:23 AM, BeagleBen [email protected]
wrote:

Is it possible to link to an external site using the link_to image_tag

<%= link_to image_tag (“Twitter.png”), https://twitter.com/ %>

You need to put the URL in quotes. Otherwise Ruby will try to
interpret that as a variable or a method call, and fail.

I would bet you were getting some error message when Rails tried to
render that page. When having a problem, error messages are usually
very helpful to include. What was it in this case? Probably
something like “no such method or local variable”, pointing at the
URL, right?

Also, just a bit of extra bonus advice that will help you later: you
almost got bitten by a Ruby Gotcha. When you use parentheses on a
method call (like that of image_tag above), avoid putting a space
before the opening paren. This may seem like style nitpicking, but in
fact it is one of those areas where Ruby is unexpectedly
whitespace-sensitive. It didn’t matter in this instance because there
was only one argument. However, suppose you call a method with two,
like a trivial one to add two numbers. If you call it as “add 1, 2”,
omitting the parens, that’s fine. If you call it as “add(1, 2)”,
using no spaces around the parens (which seems to be typical Ruby
style), or even “add( 1, 2 )”, putting spaces inside the parens,
fine. But if you call it as “add (1, 2)”, then it thinks you’re
trying to pass the add method only one parameter instead of the two
it expects. Even if add could handle receiving only one param (like
if it had a default value for the second), that one param would be
“(1, 2)”… which is not a valid expression in Ruby.

For more gotchas, see

(the slides from my Ruby Gotchas presentation).

-Dave


Dave A., the T. Rex of Codosaurus LLC,
secret-cleared freelance software developer
taking contracts in or near NoVa or remote.
See information at http://www.Codosaur.us/.

Dave

Thank you so much for your help, normally work with asp.net mvc, but
relly
enjoying my return to rails

Steven