Search code examples
ruby-on-railsform-helpers

How to create a rails button with an icon and text?


How would you create this button using a rail helper?

<button type="submit" class="btn">
 Create My Account <i class="fa"></i>
</button>

So far I have

<%= f.submit "Create My Account", :class => "btn" %>

Solution

  • You can use the button form helper and pass it a block.

    <%= f.button class: 'btn' do %>
      Create My Account <i class="fa"></i>
    <% end %>
    

    See more at http://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-button