Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails and bootstrap - Add HTML tags to a submit button text

I have a form for a like/unlike button using ajax :

= form_for like, :html => { :method => :delete}, :remote => true do |f| = f.submit pluralize(@video.likes.count, 'like'), :class => "btn btn-warning btn-mini", "data-disable-with"=> "Just a moment..." 

The form works perfectly.

I would like to add an icon in front of the text in the submit button. The haml code for adding the icon is the following (twitter bootstrap) :

%i.icon-heart.icon-white 

Is there a way to add this html to the button? I tried adding it as plain html, but rails rendered it as text.

UPDATE

I have manage to encapsulate the submit button in a span class which contains the icon and the appropriate styling. I now need to remove every styling on the button...

%span.btn.btn-danger.btn-mini   %i.icon-heart.icon-white   = f.submit pluralize(@video.likes.count, 'like') 
like image 626
Justin D. Avatar asked Jul 22 '12 21:07

Justin D.


1 Answers

Thanks to ismaelga, I found this SO question.

This is the solution :

<%= button_tag(type: 'submit', class: "btn btn-primary") do %>  <i class="icon-ok icon-white"></i> Save <% end %> 
like image 170
Justin D. Avatar answered Oct 05 '22 13:10

Justin D.