Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 744
steel Avatar asked Feb 11 '23 01:02

steel


1 Answers

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

like image 132
Allan W Smith Avatar answered Feb 23 '23 04:02

Allan W Smith