aboutsummaryrefslogblamecommitdiffstats
path: root/actionpack/lib/action_view/helpers/tags/text_field.rb
blob: 0f81726eb44ed89e81561ee409d4396d5121bbb6 (plain) (tree)
1
2
3
4
5
6
7
8
9


                 
                                     
                  


                                                                                                             
                                         
                                                                                                                 



                                                                      



                      
                                                                                    
           



         
module ActionView
  module Helpers
    module Tags
      class TextField < Base #:nodoc:
        def render
          options = @options.stringify_keys
          options["size"] = options["maxlength"] || DEFAULT_FIELD_OPTIONS["size"] unless options.key?("size")
          options = DEFAULT_FIELD_OPTIONS.merge(options)
          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

        private

        def field_type
          @field_type ||= self.class.name.split("::").last.sub("Field", "").downcase
        end
      end
    end
  end
end