Manage your model images with RMagick and CarrierWave.
-
Add to your Gemfile:
gem 'crimagify'
-
Run
Bundle
-
Execute:
rails generate crimagify:install
-
Run migrations:
rake db:migrate
-
Run seeds:
rake db:seed
Add to your routes.rb: mount Crimagify::Engine => "/crimagify", :as => "crimagify"
Add to your model:
... extend Crimagify::DinamicImageMethods has_many :crimagify_images, :as => :parent, :dependent => :destroy, :class_name => Crimagify::Image build_methods_images ...
Add to your controller:
... #For Action Create: if @object.save Crimagify::ImageFunctions::create_new_images(@object, params) end ... ... #For Action Update: id @object.update_attributes(params[:object]) Crimagify::ImageFunctions::update_images(@object, params) end ...
Add to application.js://= require crimagify/application
Add to application.css:*= require crimagify/application
Edit the file generated for the gem: config/crimagify_versions.yml, with the specific format mantaining the same ratio for all versions in each blocks, adding models that use images:
User: imgA: user: width: 100 height: 100 big: width: 500 height: 500 imgB: big: width: 800 height: 500 small: width: 400 height: 250 Product: imgA: big: width: 600 height: 300
Add to your form view:
<%= form_for(@object) do |f| %> ... <%= images_id(@object) %> <%= image_cropper(@object, { image_name: "imgA", ratio: :big}) %> #The attributes "imgA" and :big or :small are defined <%= image_cropper(@object, { image_name: "imgB", ratio: :small}) %> #into file config/crimagify_versions.yml generated for the gem ... <% end %>