content_tag not working with f.submit on rails 5.1

267 Views Asked by At

I would like to add a bootstrap styling to my f.submit button with ruby on rails form helpers. But the code below not working for me. Does anyone have an idea how to do this correctly with rails 5.1?

<%= f.submit content_tag(:i, "Add to Cart", class: ["fa", "fa-shopping-cart"]), :class => "primary-btn add-to-cart"%>

I also tried this, it is not working neither.

<%= f.submit "Add to Cart", :class => "primary-btn add-to-cart"  do %>
       <i class="fa fa-shopping-cart"></i>
    <% end %>

I also tried using raw or HTML_safe. But no luck.

1

There are 1 best solutions below

0
On

Submit doesn't have an option to include tags according to documantation as no block there in the source

You can try:

<%= f.button :class => "primary-btn add-to-cart"  do %>
   <i class="fa fa-shopping-cart">Add to Cart</i>
<% end %>