Adding span tag in Rails link_to

tvalent2 picture tvalent2 · Sep 27, 2011 · Viewed 30.4k times · Source

I've looked on SO about how to add a <span> tag but I didn't see an example that placed the <span> where I want using Rails 3 link_to:

<a href="#" class="button white"><span id="span">My span&nbsp;</span>My data</a>

I tried something like:

<%= link_to(content_tag{:span => "My span&nbsp;", :id => "span"} @user.profile.my_data, "#", {:class => "button white"}) %>

But that didn't work.

Answer

mu is too short picture mu is too short · Sep 27, 2011

link_to can take a block so I think you're after something like this:

<%= link_to '#', :class => 'button white' do %>
    <span id="span">My span&nbsp;</span><%= @user.profile.my_data %>
<% end %>