method
file_field_tag
v1.0.0 -
Show latest stable
- Class:
ActionView::Helpers::FormTagHelper
file_field_tag(name, options = {})public
Creates a file upload field.
If you are using file uploads then you will also need to set the multipart option for the form:
<%= form_tag { :action => "post" }, { :multipart => true } %> <label for="file">File to Upload</label> <%= file_field_tag "file" %> <%= submit_tag %> <%= end_form_tag %>
The specified URL will then be passed a File object containing the selected file, or if the field was left blank, a StringIO object.
2Notes
HTML5 support
To support multiple file selection simply pass :multiple => true in the options hash:
file_field_tag 'file', :accept => 'image/jpeg', :multiple => true
Multiple files
To use multiple file upload need to use variable_name[].
==== like this:
file_field_tag 'files[]', :multiple => true
==== and in controller:
if !params[ :files ].nil?
params[ :files ].each{ |file|
# do your staff
}
end