diff options
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 7 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/form_tag_helper.rb | 4 |
2 files changed, 10 insertions, 1 deletions
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 |