diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-01-16 20:14:56 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-01-17 00:05:29 -0300 |
commit | 68b870f6be0eff3de6b3dfb6ba64b253419260ee (patch) | |
tree | 53959ae319e8c171b54f1d4775d51566f9d75209 /actionpack/lib | |
parent | 6aeb799866ae08a0e8944cc23a48f1616b60d560 (diff) | |
download | rails-68b870f6be0eff3de6b3dfb6ba64b253419260ee.tar.gz rails-68b870f6be0eff3de6b3dfb6ba64b253419260ee.tar.bz2 rails-68b870f6be0eff3de6b3dfb6ba64b253419260ee.zip |
Extract FileField
Diffstat (limited to 'actionpack/lib')
4 files changed, 16 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 1fbd3f80e6..9c8966e528 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -738,7 +738,7 @@ module ActionView # # => <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+) diff --git a/actionpack/lib/action_view/helpers/tags.rb b/actionpack/lib/action_view/helpers/tags.rb index b663f8b68f..5b43f43fea 100644 --- a/actionpack/lib/action_view/helpers/tags.rb +++ b/actionpack/lib/action_view/helpers/tags.rb @@ -6,6 +6,7 @@ module ActionView 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 diff --git a/actionpack/lib/action_view/helpers/tags/file_field.rb b/actionpack/lib/action_view/helpers/tags/file_field.rb new file mode 100644 index 0000000000..56442e1c14 --- /dev/null +++ b/actionpack/lib/action_view/helpers/tags/file_field.rb @@ -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 diff --git a/actionpack/lib/action_view/helpers/tags/text_field.rb b/actionpack/lib/action_view/helpers/tags/text_field.rb index 758fd636f2..0f81726eb4 100644 --- a/actionpack/lib/action_view/helpers/tags/text_field.rb +++ b/actionpack/lib/action_view/helpers/tags/text_field.rb @@ -7,7 +7,7 @@ module ActionView 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 @@ module ActionView 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 |