aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb7
-rw-r--r--actionpack/lib/action_view/helpers/form_tag_helper.rb4
3 files changed, 12 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 8fb10b5dcb..0a53072233 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added FormHelper#file_field and FormTagHelper#file_field_tag for creating file upload fields
+
* Added :order option for date_select that allows control over the order in which the date dropdowns is used and which of them should be used #619 [Tim Bates]. Examples:
date_select("post", "written_on", :order => [:day, :month, :year])
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 36e1f946f8..b5a4403f76 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -78,6 +78,11 @@ module ActionView
InstanceTag.new(object, method, self).to_input_field_tag("hidden", options)
end
+ # Works just like text_field, but returns a input tag of the "file" type instead, which won't have any default value.
+ def file_field(object, method, options = {})
+ InstanceTag.new(object, method, self).to_input_field_tag("file", options)
+ end
+
# Returns a textarea opening and closing tag set tailored for accessing a specified attribute (identified by +method+)
# on an object assigned to the template (identified by +object+). Additional options on the input tag can be passed as a
# hash with +options+.
@@ -147,7 +152,7 @@ module ActionView
html_options.merge!({ "size" => options["maxlength"]}) if options["maxlength"] && !options["size"]
html_options.delete("size") if field_type == "hidden"
html_options.merge!({ "type" => field_type})
- html_options.merge!({ "value" => value_before_type_cast }) unless options["value"]
+ html_options.merge!({ "value" => value_before_type_cast }) if options["value"].nil? || field_type == "file"
add_default_name_and_id(html_options)
tag("input", html_options)
end
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index 78123a9d87..a5b18fe7f0 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -43,6 +43,10 @@ module ActionView
text_field_tag(name, value, options.update("type" => "hidden"))
end
+ def file_field_tag(name, options = {})
+ text_field_tag(name, nil, options.update("type" => "file"))
+ end
+
def password_field_tag(name = "password", value = nil, options = {})
text_field_tag(name, value, options.update("type" => "password"))
end