Lucy
Lucy

Reputation: 31

content_tag not working with f.submit on rails 5.1

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.

Upvotes: 3

Views: 257

Answers (1)

Alexander Sysuiev
Alexander Sysuiev

Reputation: 721

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 %>

Upvotes: 1

Related Questions