Methods
- C
- N
- R
- T
- V
Included Modules
- ActionView::Helpers::ActiveModelInstanceTag
- ActionView::Helpers::TagHelper
- ActionView::Helpers::FormTagHelper
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
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1165 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
# File actionpack/lib/action_view/helpers/form_helper.rb, line 982 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!(%r\[\]$/,"") || @object_name.sub!(%r\[\]\]$/,"]") @object = retrieve_object(object) @auto_index = retrieve_autoindex(Regexp.last_match.pre_match) if Regexp.last_match end
Instance Public methods
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1135 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
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1124 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
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1107 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
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1085 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
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1035 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
# File actionpack/lib/action_view/helpers/form_helper.rb, line 991 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!(%r\[(.*)_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
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1049 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
# File actionpack/lib/action_view/helpers/form_helper.rb, line 1074 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