Class: ActionView::Helpers::InstanceTag

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n_label.rb

Instance Method Summary collapse

Instance Method Details

#to_label_tag(text = nil, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/i18n_label.rb', line 5

def to_label_tag(text = nil, options = {})
  options = options.stringify_keys
  tag_value = options.delete("value")
  name_and_id = options.dup
  name_and_id["id"] = name_and_id["for"]
  add_default_name_and_id_for_value(tag_value, name_and_id)
  options.delete("index")
  options["for"] ||= name_and_id["id"]
  
  if text.blank?
    content = method_name.humanize
    if object.respond_to?(:human_attribute_name)
      content = object.human_attribute_name(method_name)
    elsif object.class.respond_to?(:human_attribute_name)
      content = object.class.human_attribute_name(method_name)
    end
  else
    content = text.to_s
  end
  
  label_tag(name_and_id["id"], content, options)
end