No commit activity in last 3 years
No release in over 3 years
A more powerful file input.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

DEPRECATED

pretty_file_input version build

pretty_file_input is an attempt to standardize the always-problematic file input in our Rails apps.

Benefits

  • 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

Requirements

Installation

# Gemfile
gem 'pretty_file_input'

# application.css
*= require pretty_file_input

# application.js
//= require pretty_file_input

Implementation

There are a couple of ways to use this gem:

Automatic

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:

gif

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.)

Manual

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

Events

  • pfi:uploaded
  • pfi:removed

License

MIT