ImageThread
Gem for multiply file upload (for backend).
One thread (thread of images) have many images. Attach thread to your model and you get "album"
Dependencies:
- carrierwave
- foreigner
TODOs:
- Single/Multi uploaders
- Validators - size, count, format and etc
- Handle errors
- Customize uploaders
- I18n
- Reorder images in thread
- Placeholder generator for nonexistent files
- Tests!!!
- Cache thumb creation
Features
- Dynamic thumbs (i.e. thread.image[0].thumb('120x120') or thread.image[0].thumb('300x100!'))
- Settings: remove file on destroy(ex.: has_image_thread :images, delete: :file )
Examples
Installation
Add this line to your application's Gemfile:
gem 'image_thread'
And then execute:
$ bundle
Or install it yourself as:
$ gem install image_thread
Copy migrations:
rails generate image_thread:install
Then run this migration.
Usage
Setup client-side
Add js to your manifest file
require image_thread
If you use custom class for uploader (default: '.image_thread_fileupload') require only uploader without init file
require image_thread/uploader
and init uploader(s):
$(function(){
$('#custom-selector').each(function(){
$(this).fileupload({
formData: {
uploader: $(this).data('uploader'),
thread: $(this).data('thread'),
dir: $(this).data('dir')
},
inputName: $(this).data('name'),
previewCrop: true,
previewMaxWidth: 120,
previewMaxHeight: 120,
filesContainer: $(this).closest('.uploader-container').find('.files')
});
});
});
Add thread to model
- Create filed %{your_thread_name}_id in your model (Link to thread)
- Inside model class add line: has_image_thread :%{your_thread_name}
Upload files
- In form use this: image_thread_field helper(like text_field etc): form.image_thread_field(:%{your_thread_name}, options)
Contributing
- Fork it ( http://github.com//image_thread/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request