Search code examples
ruby-on-railsruby-on-rails-4simple-form

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?


Solution

  • 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