user2993456
user2993456

Reputation:

rendering a span inside of an anchor with link_to

So I just want to make the text of a link have the bootstrap class of text-muted. If I apply the class directly to the anchor tag in the link_to method of my view, it does nothing. Therefore, I am trying to nest a span into my anchor tag using the link_to, but the html will not render, even when I use the raw method.

My end goal here is to simply make the text within my About linke have the text-muted class, and have the affects actually visible.

here is my code:

 1 <div class="row-fluid">                                                           
  2   <div class="vertical-center text-center">                                     
  3     <%= form_for :search, :html => { :class => "" } do |f| %>                   
  4       <%= f.text_field :query, :placeholder => "Job Title" %><br />               
  5       <%= f.text_field :location, :placeholder => "Location" %><br />           
  6       <%= button_tag( :class => "submit-button btn btn-default", :id => "search") do %>      
  7         <span class="text-muted bold">Search</span>                             
  8       <% end %>                                                                   
  9       <%= link_to "#{ raw "<span class='text-muted bold'>About</span>" }", { :controller => :about }, :class => "btn btn-default bold", :id => "about"%> 
 10     <% end %>                                                                     
 11   </div>                                                                          
 12 </div> 

Here is what it currently looks like on the page: enter image description here

Upvotes: 0

Views: 1530

Answers (1)

Peter de Ridder
Peter de Ridder

Reputation: 2399

You can use html_safe:

"<span class='text-muted bold'>About</span>".html_safe

Or you can use a block:

<%= link_to about_path do %>
  <span class='text-muted bold'>About</span>
<% end %>

Upvotes: 3

Related Questions