Module: ActionView::Helpers::FormTagHelper

Defined in:
lib/action_view/form_helper.rb

Instance Method Summary collapse

Instance Method Details

#label_tag(name = nil, content_or_options = nil, options = nil, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/action_view/form_helper.rb', line 5

def label_tag(name = nil, content_or_options = nil, options = nil, &block)
  if block_given? && content_or_options.is_a?(Hash)
    options = content_or_options = content_or_options.stringify_keys
  else
    options ||= {}
    options = options.stringify_keys
  end
  options["for"] = sanitize_to_id(name) unless name.blank? || options.has_key?("for")
  options["id"]  = "label_#{options['for']}" if options.has_key?("for")
   :label, content_or_options || name.to_s.humanize, options, &block
end