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] method_name
[R] object
[R] object_name
Class Public methods
check_box_checked?(value, checked_value)
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1163
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 980
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 1180
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 1151
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 1155
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 1133
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 1122
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 1105
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 1083
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 = unchecked_value ? tag("input", "name" => options["name"], "type" => "hidden", "value" => unchecked_value, "disabled" => options["disabled"]) : ""
  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 1118
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 1033
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 989
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.delete("namespace")
  options["for"] ||= name_and_id["id"]

  if block_given?
    @template_object.label_tag(name_and_id["id"], options, &block)
  else
    content = if text.blank?
      object_name.gsub!(/\[(.*)_attributes\]\[\d\]/, '.\1')
      method_and_value = tag_value.present? ? "#{method_name}.#{tag_value}" : method_name

      if object.respond_to?(:to_model)
        key = object.class.model_name.i18n_key
        i18n_default = ["#{key}.#{method_and_value}".to_sym, ""]
      end

      i18n_default ||= ""
      I18n.t("#{object_name}.#{method_and_value}", :default => i18n_default, :scope => "helpers.label").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 1047
def to_number_field_tag(field_type, options = {})
  options = options.stringify_keys
  options['size'] ||= nil

  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 1057
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 1072
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", options.delete('value') || value_before_type_cast(object), options)
end
value(object)
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1142
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 1146
def value_before_type_cast(object)
  self.class.value_before_type_cast(object, @method_name)
end