Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extract FileField

  • Loading branch information...
commit 68b870f6be0eff3de6b3dfb6ba64b253419260ee 1 parent 6aeb799
Rafael Mendonça França rafaelfranca authored
2  actionpack/lib/action_view/helpers/form_helper.rb
View
@@ -738,7 +738,7 @@ def hidden_field(object_name, method, options = {})
# # => <input type="file" id="attachment_file" name="attachment[file]" class="file_input" />
#
def file_field(object_name, method, options = {})
- InstanceTag.new(object_name, method, self, options.delete(:object)).to_input_field_tag("file", options.update({:size => nil}))
+ ActionView::Helpers::Tags::FileField.new(object_name, method, self, options).render
end
# Returns a textarea opening and closing tag set tailored for accessing a specified attribute (identified by +method+)
1  actionpack/lib/action_view/helpers/tags.rb
View
@@ -6,6 +6,7 @@ module Tags
autoload :TextField, 'action_view/helpers/tags/text_field'
autoload :PasswordField, 'action_view/helpers/tags/password_field'
autoload :HiddenField, 'action_view/helpers/tags/hidden_field'
+ autoload :FileField, 'action_view/helpers/tags/file_field'
end
end
end
12 actionpack/lib/action_view/helpers/tags/file_field.rb
View
@@ -0,0 +1,12 @@
+module ActionView
+ module Helpers
+ module Tags
+ class FileField < TextField #:nodoc:
+ def render
+ @options.update(:size => nil)
+ super
+ end
+ end
+ end
+ end
+end
4 actionpack/lib/action_view/helpers/tags/text_field.rb
View
@@ -7,7 +7,7 @@ def render
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) }
+ 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)
@@ -16,7 +16,7 @@ def render
private
def field_type
- self.class.name.split("::").last.sub("Field", "").downcase
+ @field_type ||= self.class.name.split("::").last.sub("Field", "").downcase
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.