Class: Trellis::CoreComponents::File

Inherits:
Trellis::Component show all
Defined in:
lib/trellis/component_library/core_components.rb

Overview

Creates a file upload field. If you are using file uploads then you will also need to set the multipart option for the form tag:

<%= 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.

Options

  • Creates standard HTML attributes for the tag.

  • :disabled - If set to true, the user will not be able to use this input.

Examples

file_field_tag 'attachment'
# => <input id="attachment" name="attachment" type="file" />

file_field_tag 'avatar', :class => 'profile-input'
# => <input class="profile-input" id="avatar" name="avatar" type="file" />

file_field_tag 'picture', :disabled => true
# => <input disabled="disabled" id="picture" name="picture" type="file" />

file_field_tag 'resume', :value => '~/resume.doc'
# => <input id="resume" name="resume" type="file" value="~/resume.doc" />

file_field_tag 'user_pic', :accept => 'image/png,image/gif,image/jpeg'
# => <input accept="image/png,image/gif,image/jpeg" id="user_pic" name="user_pic" type="file" /> 

file_field_tag 'file', :accept => 'text/html', :class => 'upload', :value => 'index.html'
# => <input accept="text/html" class="upload" id="file" name="file" type="file" value="index.html" />

Instance Attribute Summary

Attributes inherited from Trellis::Component

#logger, #page

Method Summary

Methods inherited from Trellis::Component

add_class_scripts_to_page, add_class_styles_to_page, add_document_modifications_to_page, add_script_links_to_page, add_scripts_to_page, add_style_links_to_page, add_styles_to_page, contained_in, depends_on, field, get_component, inherited, #initialize, is_stateful, #load_component_session_information, page_contribution, register_with_tag_context, render, #save_component_session_information, tag_name

Constructor Details

This class inherits a constructor from Trellis::Component