Module: ActionView::Helpers::InstanceTagMethods
- Extended by:
- ActiveSupport::Concern
- Includes:
- Context, CaptureHelper, FormTagHelper, TagHelper
- Defined in:
- actionpack/lib/action_view/helpers/form_helper.rb
Overview
:nodoc:
Defined Under Namespace
Modules: ClassMethods
Constant Summary
- DEFAULT_FIELD_OPTIONS =
{ "size" => 30 }.freeze
- DEFAULT_RADIO_OPTIONS =
{ }.freeze
- DEFAULT_TEXT_AREA_OPTIONS =
{ "cols" => 40, "rows" => 20 }.freeze
Constants included from TextHelper
TextHelper::AUTO_EMAIL_RE, TextHelper::AUTO_LINK_CRE, TextHelper::AUTO_LINK_RE, TextHelper::BRACKETS
Constants included from TagHelper
Constants included from ERB::Util
ERB::Util::HTML_ESCAPE, ERB::Util::JSON_ESCAPE
Instance Attribute Summary (collapse)
-
- (Object) method_name
readonly
Returns the value of attribute method_name.
-
- (Object) object_name
readonly
Returns the value of attribute object_name.
Attributes included from Context
Instance Method Summary (collapse)
-
- (InstanceTagMethods) initialize(object_name, method_name, template_object, object = nil)
A new instance of InstanceTagMethods.
- - (Object) object
- - (Object) to_boolean_select_tag(options = {})
- - (Object) to_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0")
- - (Object) to_content_tag(tag_name, options = {})
- - (Object) to_input_field_tag(field_type, options = {})
- - (Object) to_label_tag(text = nil, options = {}, &block)
- - (Object) to_number_field_tag(field_type, options = {})
- - (Object) to_radio_button_tag(tag_value, options = {})
- - (Object) to_text_area_tag(options = {})
- - (Object) value(object)
- - (Object) value_before_type_cast(object)
Methods included from ActiveSupport::Concern
append_features, extended, included
Methods included from FormTagHelper
#check_box_tag, #email_field_tag, #field_set_tag, #file_field_tag, #form_tag, #hidden_field_tag, #image_submit_tag, #label_tag, #number_field_tag, #password_field_tag, #radio_button_tag, #range_field_tag, #search_field_tag, #select_tag, #submit_tag, #telephone_field_tag, #text_area_tag, #text_field_tag, #url_field_tag
Methods included from TextHelper
#auto_link, #concat, #current_cycle, #cycle, #excerpt, #highlight, #pluralize, #reset_cycle, #safe_concat, #simple_format, #truncate, #word_wrap
Methods included from SanitizeHelper
#sanitize, #sanitize_css, #strip_links, #strip_tags
Methods included from UrlHelper
#button_to, #current_page?, #link_to, #link_to_if, #link_to_unless, #link_to_unless_current, #mail_to, #url_for, #url_options
Methods included from TagHelper
#cdata_section, #content_tag, #escape_once, #tag
Methods included from CaptureHelper
#capture, #content_for, #content_for?, #flush_output_buffer, #with_output_buffer
Methods included from ERB::Util
Methods included from ActionDispatch::Routing::UrlFor
Methods included from ActionDispatch::Routing::PolymorphicRoutes
#polymorphic_path, #polymorphic_url
Methods included from Context
Instance Attribute Details
- (Object) method_name (readonly)
Returns the value of attribute method_name
854 855 856 |
# File 'actionpack/lib/action_view/helpers/form_helper.rb', line 854 def method_name @method_name end |
- (Object) object_name (readonly)
Returns the value of attribute object_name
854 855 856 |
# File 'actionpack/lib/action_view/helpers/form_helper.rb', line 854 def object_name @object_name end |
Instance Method Details
- (InstanceTagMethods) initialize(object_name, method_name, template_object, object = nil)
A new instance of InstanceTagMethods
860 861 862 863 864 865 866 867 868 869 870 871 |
# File 'actionpack/lib/action_view/helpers/form_helper.rb', line 860 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 = object if @object_name.sub!(/\[\]$/,"") || @object_name.sub!(/\[\]\]$/,"]") if (object ||= @template_object.instance_variable_get("@#{Regexp.last_match.pre_match}")) && object.respond_to?(:to_param) @auto_index = 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 end |
- (Object) object
994 995 996 997 998 999 1000 |
# File 'actionpack/lib/action_view/helpers/form_helper.rb', line 994 def object @object || @template_object.instance_variable_get("@#{@object_name}") rescue NameError # As @object_name may contain the nested syntax (item[subobject]) we # need to fallback to nil. nil end |
- (Object) to_boolean_select_tag(options = {})
977 978 979 980 981 982 983 984 985 986 987 988 |
# File 'actionpack/lib/action_view/helpers/form_helper.rb', line 977 def to_boolean_select_tag( = {}) = .stringify_keys add_default_name_and_id() value = value(object) tag_text = "<select" tag_text << () 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 |
- (Object) to_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0")
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 |
# File 'actionpack/lib/action_view/helpers/form_helper.rb', line 955 def to_check_box_tag( = {}, checked_value = "1", unchecked_value = "0") = .stringify_keys ["type"] = "checkbox" ["value"] = checked_value if .has_key?("checked") cv = .delete "checked" checked = cv == true || cv == "checked" else checked = self.class.check_box_checked?(value(object), checked_value) end ["checked"] = "checked" if checked if ["multiple"] add_default_name_and_id_for_value(checked_value, ) .delete("multiple") else add_default_name_and_id() end hidden = tag("input", "name" => ["name"], "type" => "hidden", "value" => ['disabled'] && checked ? checked_value : unchecked_value) checkbox = tag("input", ) (hidden + checkbox).html_safe end |
- (Object) to_content_tag(tag_name, options = {})
990 991 992 |
# File 'actionpack/lib/action_view/helpers/form_helper.rb', line 990 def to_content_tag(tag_name, = {}) content_tag(tag_name, value(object), ) end |
- (Object) to_input_field_tag(field_type, options = {})
907 908 909 910 911 912 913 914 915 916 917 918 919 |
# File 'actionpack/lib/action_view/helpers/form_helper.rb', line 907 def to_input_field_tag(field_type, = {}) = .stringify_keys ["size"] = ["maxlength"] || DEFAULT_FIELD_OPTIONS["size"] unless .key?("size") = DEFAULT_FIELD_OPTIONS.merge() if field_type == "hidden" .delete("size") end ["type"] ||= field_type ["value"] = .fetch("value"){ value_before_type_cast(object) } unless field_type == "file" ["value"] &&= html_escape(["value"]) add_default_name_and_id() tag("input", ) end |
- (Object) to_label_tag(text = nil, options = {}, &block)
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 |
# File 'actionpack/lib/action_view/helpers/form_helper.rb', line 873 def to_label_tag(text = nil, = {}, &block) = .stringify_keys tag_value = .delete("value") name_and_id = .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) .delete("index") ["for"] ||= name_and_id["id"] if block_given? label_tag(name_and_id["id"], , &block) else content = if text.blank? I18n.t("helpers.label.#{object_name}.#{method_name}", :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, ) end end |
- (Object) to_number_field_tag(field_type, options = {})
921 922 923 924 925 926 927 |
# File 'actionpack/lib/action_view/helpers/form_helper.rb', line 921 def to_number_field_tag(field_type, = {}) = .stringify_keys if range = .delete("in") || .delete("within") .update("min" => range.min, "max" => range.max) end to_input_field_tag(field_type, ) end |
- (Object) to_radio_button_tag(tag_value, options = {})
929 930 931 932 933 934 935 936 937 938 939 940 941 942 |
# File 'actionpack/lib/action_view/helpers/form_helper.rb', line 929 def (tag_value, = {}) = DEFAULT_RADIO_OPTIONS.merge(.stringify_keys) ["type"] = "radio" ["value"] = tag_value if .has_key?("checked") cv = .delete "checked" checked = cv == true || cv == "checked" else checked = self.class.(value(object), tag_value) end ["checked"] = "checked" if checked add_default_name_and_id_for_value(tag_value, ) tag("input", ) end |
- (Object) to_text_area_tag(options = {})
944 945 946 947 948 949 950 951 952 953 |
# File 'actionpack/lib/action_view/helpers/form_helper.rb', line 944 def to_text_area_tag( = {}) = DEFAULT_TEXT_AREA_OPTIONS.merge(.stringify_keys) add_default_name_and_id() if size = .delete("size") ["cols"], ["rows"] = size.split("x") if size.respond_to?(:split) end content_tag("textarea", html_escape(.delete('value') || value_before_type_cast(object)), ) end |
- (Object) value(object)
1002 1003 1004 |
# File 'actionpack/lib/action_view/helpers/form_helper.rb', line 1002 def value(object) self.class.value(object, @method_name) end |
- (Object) value_before_type_cast(object)
1006 1007 1008 |
# File 'actionpack/lib/action_view/helpers/form_helper.rb', line 1006 def value_before_type_cast(object) self.class.value_before_type_cast(object, @method_name) end |