DEPRECATED
pretty_file_input is an attempt to standardize the always-problematic file input in our Rails apps.
- Immediate uploads via AJAX for
persisted?
records - Upload percentage displayed while uploading
- Identical user interface (without AJAX uploads) for non-
persisted?
records - Use your existing models and controllers, no changes necessary
- carrierwave
- simple_form (if using the "Automatic" implementation below)
- jQuery
- jquery.form
# Gemfile
gem 'pretty_file_input'
# application.css
*= require pretty_file_input
# application.js
//= require pretty_file_input
There are a couple of ways to use this gem:
By taking advantage of the included simple_form input class, you can start using pretty_file_input with as little as one line of code:
f.input :avatar, as: :pretty_file_input
The resulting behavior will depend on whether or not the parent object is already persisted in the database.
For existing records, pretty_file_input will upload and remove files immediately, displaying some nice UI feedback along the way:
For new records, pretty_file_input will not perform any AJAX requests. (Carrierwave stores files alongside your database records, so it's impossible to upload a file before its associated record has been created.)
If your use case doesn't fit the patterns above, you can use the "Manual" integration with pretty_file_input. PrettyFileInput::Views::Component
is a Fortitude widget that can be customized with the following options:
:name, # input name that will be sent to the server
persisted: false, # is parent object is not persisted, no AJAX calls will be made
filename: nil, # pre-populate the filename span
method: nil, # override the parent form's method
action: nil, # override the parent form's action
additional_params: {} # additional parameters to be sent to server with each request
pfi:uploaded
pfi:removed