steel
steel

Reputation: 12520

Rails: Simple Form Custom Label Not Working

I'd like to create a custom label for a simple form field. For some reason, the below code isn't creating that label. It's still using the default label. I must be missing something easy.

Simple Form 3.1

<%= simple_form_for "#" do |f| %>
  <%= f.input :street, label: "Custom Label"  %>
  ...
<% end %>

How can I create a custom label for my inputs in Simple Form?

Upvotes: 4

Views: 6476

Answers (2)

Mike T
Mike T

Reputation: 2636

You can now pass a label as argument. So the syntax as shown in the question (from 2015) now works:

<%= f.input :street, label: "Custom Label"  %>

See the "Usage" section of the readme.

Upvotes: 1

Allan W Smith
Allan W Smith

Reputation: 756

You need to use a label helper along with your input helper:

<%= simple_form_for "#" do |f| %>
   <%= f.label :street, 'Custom label' %>
   <%= f.input :street, as: :string, label: false %>
<% end %>

You can also directly specify input types ie. f.text_field - More info : http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html

Upvotes: 7

Related Questions