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"


219
220
221
222
223
224
225
226
227
228
# File 'lib/simple_form/form_builder.rb', line 219

def label(attribute_name, *args)
  return super if args.first.is_a?(String)
  options = args.extract_options!
  options[:label_html] = options.dup
  options[:label]      = options.delete(:label)
  options[:required]   = options.delete(:required)
  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