Method: FileColumnHelper#file_column_field
- Defined in:
- lib/file_column_helper.rb
#file_column_field(object, method, options = {}) ⇒ Object
Use this helper to create an upload field for a file_column attribute. This will generate an additional hidden field to keep uploaded files during form-redisplays. For example, when called with
<%= file_column_field("entry", "image") %>
the following HTML will be generated (assuming the form is redisplayed and something has already been uploaded):
<input type="hidden" name="entry[image_temp]" value="..." />
<input type="file" name="entry[image]" />
You can use the option argument to pass additional options to the file-field tag.
Be sure to set the enclosing form’s encoding to ‘multipart/form-data’, by using something like this:
<%= form_tag {:action => "create", ...}, :multipart => true %>
25 26 27 28 |
# File 'lib/file_column_helper.rb', line 25 def file_column_field(object, method, ={}) result = ActionView::Helpers::InstanceTag.new(object.dup, method.to_s+"_temp", self).to_input_field_tag("hidden", {}) result << ActionView::Helpers::InstanceTag.new(object.dup, method, self).to_input_field_tag("file", ) end |