Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

link_to image_tag with inner text or html in rails

I want to output the following with Ruby on Rails link_to and image_tag methods:

<a href="#">Lorem Ipsum <img src="/images/menu-arrow-down.gif"></a> 

What would be a good way in Rails?

like image 966
useranon Avatar asked Mar 22 '11 05:03

useranon


2 Answers

You can use blocks as an alternative to the string interpolation with correct usage html_safe. For example:

<%= link_to '#' do %>   Lorem Ipsum <%= image_tag('/images/menu-arrow-down.gif') %> <% end %> 
like image 130
Kevin Sylvestre Avatar answered Oct 08 '22 19:10

Kevin Sylvestre


Or a shorter way is

<%= link_to image_tag('image/someimage.png') + "Some text", some_path %> 
like image 43
Fazley Avatar answered Oct 08 '22 19:10

Fazley