simple_form custom inputs to get image/link previews with file uploads.
simple_form custom inputs to get image/link previews with file uploads.
A set of simple_form (~> 4.1) custom inputs to get image previews or a link to uploaded file.
This gem uses the simple_form ability to write your own form tags (check the simple_form-bootstrap example). In 90% of cases, you need some kind of preview when it comes to uploaded files (avatar, images, docs, etc..), why should I write the same markup each time?
There're only two new file inputs:
ImagePreview: guess what? when you edit an entry that contains an uploaded image, it will be shown (how many times did you this in a CMS?)AttachmentPreview: this is a generic upload field, it will show a direct link to the file, so you can check what was uploaded.Simply add gem 'simple_form_fancy_uploads' to your Gemfile and run bundle install
Here's a basic example, as you can see, it's just a matter of specify the input as :image_preview or :attachment_preview. If using :image_preview, you can also specify a :preview_version => :some_version_name inside the :input_html Hash. This will let you to show a custom version generated with Carrierwave. Nice, isn't it?
If you need to fallback on Carrierwave's #default_url method to show a default image defined in your upload class, set :use_default_url => true in the options hash.
If you want, you can pass the preview_url to the image on the input_html options. This might be useful when you don't have a model binded to the form.
To get it work, you need:
bundle installrspec specCopyright (c) 2014 Andrea Pavoni http://andreapavoni.com
No open issues yet, or sync has not completed.