Method: SimpleForm::FormBuilder#label

Defined in:
lib/simple_form/form_builder.rb

#label(attribute_name, *args) ⇒ Object

Creates a default label tag for the given attribute. You can give a label through the :label option or using i18n. All the given options are sent as :label_html.

Examples

f.label :name                     # Do I18n lookup
f.label :name, "Name"             # Same behavior as Rails, do not add required tag
f.label :name, label: "Name"      # Same as above, but adds required tag

f.label :name, required: false
f.label :name, id: "cool_label"


323
324
325
326
327
328
329
330
331
332
# File 'lib/simple_form/form_builder.rb', line 323

def label(attribute_name, *args)
  return super if args.first.is_a?(String) || block_given?

  options = args.extract_options!.dup
  options[:label_html] = options.except(:label, :label_text, :required, :as)

  column      = find_attribute_column(attribute_name)
  input_type  = default_input_type(attribute_name, column, options)
  SimpleForm::Inputs::Base.new(self, attribute_name, column, input_type, options).label
end