Forum: Ruby on Rails Using link_to with an image tag & link text

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Pete G. (Guest)
on 2006-06-10 02:28
Hi ,
I was trying to use link_to along with image_tag
to setup a link that would open in an external window.
But I was unable to make a link using both text & an image
So my current workaround looks like this inside a partial
where link is http://foo.com & text would be descriptive

  <img src="images/arrow.gif" border="0"/> <%= link_to(text, link,
:popup =>true) %>

ideally i would like to use the image_tag inside the link_to & make it
cleaner.

Would appreciate help from anyone on this,

Thanks,
 Pete
John G. (Guest)
on 2006-06-10 02:34
Pete Gajria wrote:
> Hi ,
> I was trying to use link_to along with image_tag
> to setup a link that would open in an external window.
> But I was unable to make a link using both text & an image

What does the original code look like? You should be able to do
something like:

link_to( image_tag(...), url )
Pete G. (Guest)
on 2006-06-10 03:50
John Gray wrote:
> Pete Gajria wrote:
>> Hi ,
>> I was trying to use link_to along with image_tag
>> to setup a link that would open in an external window.
>> But I was unable to make a link using both text & an image
>
> What does the original code look like? You should be able to do
> something like:
>
> link_to( image_tag(...), url )

I tried the above which gives me an image with an href
what i want is an image next to some text both of which link to the same
url
so something like this below...which didnt work for me
 link_to( image_tag(...), url, text )

aka

link_to( image_tag(...), "http://www.cnn.com", "Read more news" )
John G. (Guest)
on 2006-06-10 03:56
Pete Gajria wrote:
> John Gray wrote:
>> Pete Gajria wrote:
>>> Hi ,
>>> I was trying to use link_to along with image_tag
>>> to setup a link that would open in an external window.
>>> But I was unable to make a link using both text & an image
>>
>> What does the original code look like? You should be able to do
>> something like:
>>
>> link_to( image_tag(...), url )
>
> I tried the above which gives me an image with an href
> what i want is an image next to some text both of which link to the same
> url
> so something like this below...which didnt work for me
>  link_to( image_tag(...), url, text )
>
> aka
>
> link_to( image_tag(...), "http://www.cnn.com", "Read more news" )

Ah, I see. The only way I know to do that is to use two link_to calls,
one as above and another using a text string instead of image_tag.
Rob B. (Guest)
on 2006-06-27 00:59
(Received via mailing list)
On Jun 9, 2006, at 7:56 PM, John Gray wrote:

>>>
>>
>> link_to( image_tag(...), "http://www.cnn.com", "Read more news" )
>
> Ah, I see. The only way I know to do that is to use two link_to calls,
> one as above and another using a text string instead of image_tag.

Not so, just do this: (note the '+' btwn image_tag and text)

link_to( image_tag(...) + "http://www.cnn.com", "Read more news" )

-Rob
Justin C. (Guest)
on 2006-07-05 18:26
(Received via mailing list)
Try doing this:

link_to "Read more news #{image_tag(....)}", url )

Justin
This topic is locked and can not be replied to.