Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 - link_to with image_tag + text

<%= link_to ((image_tag 'image.png'), 
        url_for({:controller => 'controller_name', :action => 'action_name'}), 
            :class => 'quick', 
            :remote => true) %>

This part of code will generate me image.png as a link. I would need to this image append some text (image + text), I tried something like a:

<%= link_to ((image_tag 'image.png', 'text'), 
        url_for({:controller => 'controller_name', :action => 'action_name'}), 
            :class => 'quick', 
            :remote => true) %>

And similar ways, but each of these attempts ended with an error message about bad syntax... Could anyone help me, please, how I should set it right?

Thanks in advance.

like image 377
user1946705 Avatar asked Sep 14 '11 10:09

user1946705


3 Answers

Try this.

<%= link_to image_tag('/images/image.png') + "some extra text", url_for({:controller => 'controller_name', :action => 'action_name'}), :class => 'quick', :remote => true %>
like image 181
Muhammad Sannan Khalid Avatar answered Nov 10 '22 10:11

Muhammad Sannan Khalid


A slightly sexier solution?

<%= link_to image_tag("image.png", :alt => "Image Description", :class => "css"), root_path %>
like image 39
Andrew Hendrie Avatar answered Nov 10 '22 12:11

Andrew Hendrie


Try this:

<%= link_to (image_tag('image.png') + text, 
        url_for({:controller => 'controller_name', :action => 'action_name'}), 
            :class => 'quick', 
            :remote => true) %>

The first argument is the text part and with image_tag you create HTML, but you can easily append stuff.

like image 35
ayckoster Avatar answered Nov 10 '22 10:11

ayckoster