AlterFormImages
More perfect decision for loading image in form with preview. This gem using several simple things that are bundled in small flexible plugin for Rails.
Installation
Add this line to your application's Gemfile:
gem 'alter_form_images'
And then execute:
$ bundle
Or install it yourself as:
$ gem install alter_form_images
Usage
For start using provided tweaks add require js in your application.js:
//= require alter_form_images
Then add require css in your application.css:
*= require alter_form_images
And now we need to do the last step with example situation: you has User model with avatar attachment and for setting it in form add follow lines of code:
f.image_fields_for :avatar
You of course may do some configuration in this point:
f.image_fields_for :avatar, {
width: 100, # Width of preview image
height: 100, # Height of preview image
default_image: 'default_image.png', # Url to default image
preview_style: :original # Style of image for preview in edit form
}
Contributing
- Fork it
- 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