Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added FormHelper#file_field and FormTagHelper#file_field_tag for crea…

…ting file upload fields

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@750 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit df7f3455a1f850649ad7d4c0c37ccab178717956 1 parent 94b5e57
@dhh dhh authored
View
2  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])
View
7 actionpack/lib/action_view/helpers/form_helper.rb
@@ -78,6 +78,11 @@ def hidden_field(object, method, options = {})
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 @@ def to_input_field_tag(field_type, options = {})
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
View
4 actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -43,6 +43,10 @@ def hidden_field_tag(name, value = nil, options = {})
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
Please sign in to comment.
Something went wrong with that request. Please try again.