Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed font-awesome icons into submit_tag

Trying to user font awesome icons for my buttons but I cant get it to show in the submit_tag

 <%= submit_tag icon("search"), class: "btn-primary", style:"width:40px;" %>

output:

 <input class="btn-primary" name="commit" style="width:40px;" type="submit" value="&lt;i class='icon-search' style='font-size:1em' &gt;&lt;/i&gt;">

helper:

def icon(name, size=1)
  #icon("camera-retro")
  #<i class="icon-camera-retro"></i> 

  html = "<i class='icon-#{name}' "
  html += "style='font-size:#{size}em' "
  html += "></i>"
  html.html_safe
end

when I remove the html.html_safe line of the helper I get the same thing. its like html_safe is not working. I have also tried html = raw(html) with no effect either.

like image 605
ajbraus Avatar asked Aug 02 '12 17:08

ajbraus


People also ask

How do I put font-awesome icon into input field?

The font-awesome icon can be placed by using the fa prefix before the icon's name. Example: In this example, we will take a form where the input field is necessary. After that, we will place the font-awesome icon inside the input field. We will use the CDN link to use the font-awesome icons.

How do I overlay font-awesome icons?

To stack multiple icons, use the fa-stack class on the parent HTML element of the 2 icons you want to stack. Then add the fa-stack-1x class for the regularly sized icon and add the fa-stack-2x class for the larger icon. fa-inverse can be added to the icon with the fa-stack-1x to help with a knock-out looking effect.


1 Answers

Input submit tags don't allow nested HTML, which you need to show an icon.

Try using a button instead:

<button class='btn btn-primary' style='width:40px;'>
  <%= icon("search") %>
</button>

It's worth noting some differences between the behaviour of button tags and input submit tags. Check out this SO question for a bunch of great details. I personally haven't had issues using button tags in my applications. YMMV with respect to different browsers and such, though.

like image 176
BaronVonBraun Avatar answered Sep 21 '22 01:09

BaronVonBraun