I want to add an icon to a button in ruby on rails. Currently I've tried the following:
<%= button_to raw("<i class=\"icon-arrow-up\"></i>"),
{:controller => 'events', :action => "upvoteEvent", :method => "put",
:id => @event.id, :uid => current_user.id},
{:class => "btn btn-success"}%>
which produces the following html:
<form action="/events/upvoteEvent?id=17&method=put&uid=7" class="button_to" method="post"><div><input class="btn btn-success" type="submit" value="<i class="icon-arrow-up"></i>" /><input name="authenticity_token" type="hidden" value="FsVUPiYl0cK666pn8hqo6AU9/HK0CweZ/nsXqwOWZzU=" /></div></form>
I've followed the solution posted here: https://stackoverflow.com/a/10468935/1385324, but it won't work for me. I have also tested that the Bootstrap CSS is working, by simply inserting an icon anywhere else on the site.
Thanks for any help!
You could also try this:
<%= link_to 'Upvote <i class="icon-arrow-up"></i>'.html_safe, 'events/upvoteEvent', class: => 'btn btn-success' %>
or for a true submit button, this:
<%= button_tag(:type => 'submit', :class => 'btn btn-success') do %>
Upvote <i class="icon-up-arrow icon-white"></i>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With