marcamillion
marcamillion

Reputation: 33795

How do I create this HTML5 button with an icon with rails form helper?

This is the output I desire:

<button type="submit" class="btn btn-large btn-search btn-primary">
  <i class="icon icon-search"></i> Find Your Apartment
</button>

If I were doing this for a link, instead of a button, I would probably do something like this:

<%= link_to root_path do %>
  <i class="icon icon-search"></i> Find Your Apartment
<% end %>

But given that I am using Rails form helpers, I am not quite sure how to do this with a f.submit.

I tried:

<%= f.submit, :class => "btn btn-large btn-search btn-primary" do %>
  <i class="icon icon-search"></i> Find Your Apartment
<% end %>

That gave me a syntax error.

Thoughts?

Edit 1:

For what it's worth, this doesn't give me the syntax error but it doesn't render the icon or the "Find Your Apartment" text:

<%= f.submit "Find Your Apartment", :class => "btn btn-large btn-search btn-primary" do %>
  <i class="icon icon-search"></i> Find Your Apartment
<% end %>

Upvotes: 3

Views: 1281

Answers (1)

rails_id
rails_id

Reputation: 8220

you can use button tag

<%= button_tag(type: 'submit', class: "btn btn-large btn-search btn-primary") do %>
 <i class="icon icon-search"></i> Find Your Apartment
<% end %>

Upvotes: 10

Related Questions