Richlewis
Richlewis

Reputation: 15374

Add font awesome icons to a form label

Is it possible to use font awesome icons within a label when creating a form for example.

if my form looks like this

<%= f.label :email %>
<%= f.email_field :email, :autofocus => true %>

How would i add the i class to the label?

I have tried this

<%= f.label :email, :class => 'icon-user' %>
<%= f.email_field :email, :autofocus => true %>

but this doesn't work?

Upvotes: 4

Views: 2816

Answers (1)

DMKE
DMKE

Reputation: 4603

Try something like this (assuming email is a field of class User):

<%= f.label :email do %>
  <i class="icon-user"></i>
  <%= User.human_attribute_name :email %>
<%- end -%>

Upvotes: 5

Related Questions