Methods
C
N
R
T
V
Included Modules
Constants
DEFAULT_FIELD_OPTIONS = { "size" => 30 }
DEFAULT_RADIO_OPTIONS = { }
DEFAULT_TEXT_AREA_OPTIONS = { "cols" => 40, "rows" => 20 }
Attributes
[R] object
[R] method_name
[R] object_name
Class Public methods
check_box_checked?(value, checked_value)
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1130
def check_box_checked?(value, checked_value)
  case value
  when TrueClass, FalseClass
    value
  when NilClass
    false
  when Integer
    value != 0
  when String
    value == checked_value
  when Array
    value.include?(checked_value)
  else
    value.to_i != 0
  end
end
new(object_name, method_name, template_object, object = nil)
# File actionpack/lib/action_view/helpers/form_helper.rb, line 959
def initialize(object_name, method_name, template_object, object = nil)
  @object_name, @method_name = object_name.to_s.dup, method_name.to_s.dup
  @template_object = template_object
  @object_name.sub!(/\[\]$/,"") || @object_name.sub!(/\[\]\]$/,"]")
  @object = retrieve_object(object)
  @auto_index = retrieve_autoindex(Regexp.last_match.pre_match) if Regexp.last_match
end
radio_button_checked?(value, checked_value)
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1147
def radio_button_checked?(value, checked_value)
  value.to_s == checked_value.to_s
end
value(object, method_name)
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1118
def value(object, method_name)
  object.send method_name if object
end
value_before_type_cast(object, method_name)
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1122
def value_before_type_cast(object, method_name)
  unless object.nil?
    object.respond_to?(method_name + "_before_type_cast") ?
    object.send(method_name + "_before_type_cast") :
    object.send(method_name)
  end
end
Instance Public methods
retrieve_autoindex(pre_match)
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1100
def retrieve_autoindex(pre_match)
  object = self.object || @template_object.instance_variable_get("@#{pre_match}")
  if object && object.respond_to?(:to_param)
    object.to_param
  else
    raise ArgumentError, "object[] naming but object param and @object var don't exist or don't respond to to_param: #{object.inspect}"
  end
end
retrieve_object(object)
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1089
def retrieve_object(object)
  if object
    object
  elsif @template_object.instance_variable_defined?("@#{@object_name}")
    @template_object.instance_variable_get("@#{@object_name}")
  end
rescue NameError
  # As @object_name may contain the nested syntax (item[subobject]) we need to fallback to nil.
  nil
end
to_boolean_select_tag(options = {})
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1072
def to_boolean_select_tag(options = {})
  options = options.stringify_keys
  add_default_name_and_id(options)
  value = value(object)
  tag_text = "<select"
  tag_text << tag_options(options)
  tag_text << "><option value=\"false\""
  tag_text << " selected" if value == false
  tag_text << ">False</option><option value=\"true\""
  tag_text << " selected" if value
  tag_text << ">True</option></select>"
end
to_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0")
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1050
def to_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0")
  options = options.stringify_keys
  options["type"]     = "checkbox"
  options["value"]    = checked_value
  if options.has_key?("checked")
    cv = options.delete "checked"
    checked = cv == true || cv == "checked"
  else
    checked = self.class.check_box_checked?(value(object), checked_value)
  end
  options["checked"] = "checked" if checked
  if options["multiple"]
    add_default_name_and_id_for_value(checked_value, options)
    options.delete("multiple")
  else
    add_default_name_and_id(options)
  end
  hidden = tag("input", "name" => options["name"], "type" => "hidden", "value" => options['disabled'] && checked ? checked_value : unchecked_value)
  checkbox = tag("input", options)
  (hidden + checkbox).html_safe
end
to_content_tag(tag_name, options = {})
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1085
def to_content_tag(tag_name, options = {})
  content_tag(tag_name, value(object), options)
end
to_input_field_tag(field_type, options = {})
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1002
def to_input_field_tag(field_type, options = {})
  options = options.stringify_keys
  options["size"] = options["maxlength"] || DEFAULT_FIELD_OPTIONS["size"] unless options.key?("size")
  options = DEFAULT_FIELD_OPTIONS.merge(options)
  if field_type == "hidden"
    options.delete("size")
  end
  options["type"]  ||= field_type
  options["value"] = options.fetch("value"){ value_before_type_cast(object) } unless field_type == "file"
  options["value"] &&= ERB::Util.html_escape(options["value"])
  add_default_name_and_id(options)
  tag("input", options)
end
to_label_tag(text = nil, options = {}, &block)
# File actionpack/lib/action_view/helpers/form_helper.rb, line 967
def to_label_tag(text = nil, options = {}, &block)
  options = options.stringify_keys
  tag_value = options.delete("value")
  name_and_id = options.dup

  if name_and_id["for"]
    name_and_id["id"] = name_and_id["for"]
  else
    name_and_id.delete("id")
  end

  add_default_name_and_id_for_value(tag_value, name_and_id)
  options.delete("index")
  options["for"] ||= name_and_id["id"]

  if block_given?
    label_tag(name_and_id["id"], options, &block)
  else
    content = if text.blank?
      method_and_value = tag_value.present? ? "#{method_name}.#{tag_value}" : method_name
      I18n.t("helpers.label.#{object_name}.#{method_and_value}", :default => "").presence
    else
      text.to_s
    end

    content ||= if object && object.class.respond_to?(:human_attribute_name)
      object.class.human_attribute_name(method_name)
    end

    content ||= method_name.humanize

    label_tag(name_and_id["id"], content, options)
  end
end
to_number_field_tag(field_type, options = {})
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1016
def to_number_field_tag(field_type, options = {})
  options = options.stringify_keys
  if range = options.delete("in") || options.delete("within")
    options.update("min" => range.min, "max" => range.max)
  end
  to_input_field_tag(field_type, options)
end
to_radio_button_tag(tag_value, options = {})
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1024
def to_radio_button_tag(tag_value, options = {})
  options = DEFAULT_RADIO_OPTIONS.merge(options.stringify_keys)
  options["type"]     = "radio"
  options["value"]    = tag_value
  if options.has_key?("checked")
    cv = options.delete "checked"
    checked = cv == true || cv == "checked"
  else
    checked = self.class.radio_button_checked?(value(object), tag_value)
  end
  options["checked"]  = "checked" if checked
  add_default_name_and_id_for_value(tag_value, options)
  tag("input", options)
end
to_text_area_tag(options = {})
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1039
def to_text_area_tag(options = {})
  options = DEFAULT_TEXT_AREA_OPTIONS.merge(options.stringify_keys)
  add_default_name_and_id(options)

  if size = options.delete("size")
    options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
  end

  content_tag("textarea", ERB::Util.html_escape(options.delete('value') || value_before_type_cast(object)), options)
end
value(object)
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1109
def value(object)
  self.class.value(object, @method_name)
end
value_before_type_cast(object)
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1113
def value_before_type_cast(object)
  self.class.value_before_type_cast(object, @method_name)
end