Rails 3 Submit Tag + html_safe
Asked Answered
D

3

5

What's wrong with this line of code?

<%= submit_tag "Delete <i class='icon-check'></i>".html_safe, :disable_with => "Deleting", :class => "btn btn-danger"%>

This literally produces:

enter image description here

Evidently my html_safe call isn't doing anything.

Background:

I'm using Twitter Bootstrap as well as Font Awesome and I'm essentially trying to achieve a submit button with an icon inside of it.

Doorstone answered 22/8, 2012 at 16:45 Comment(0)
D
17

To extend on Lukas' answer I needed a button tag rather than an input. This code produced the effect I was looking for:

<button type="submit" class="btn btn-danger">
    Delete <i class="icon-check"></i> 
</button>

Which resulted in:

result

I found the answer I was looking for here.

Doorstone answered 22/8, 2012 at 17:18 Comment(0)
C
3

What's wrong with it? Submit button values should not contain embedded HTML code.

This is how submit button looks in HTML:

<input type="submit" value="Submit" />

HTML tags in value attributes are interpreted as text, not as HTML:

<input type="submit" value="<i>Submit</i>" />

Chicken answered 22/8, 2012 at 16:57 Comment(0)
G
2
<%= form.button :submit, class: 'btn btn-success' do %>
     <i class="fa fa-plus"></i> Add Funder <i class="fa fa-chevron-right"></i>
<% end %>

This is good answer.

Goldeneye answered 4/9, 2019 at 6:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.