Skip to content

trejo08/Crimagify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Manage your model images with RMagick and CarrierWave.

Installation

  1. Add to your Gemfile: gem 'crimagify'

  2. Run Bundle

  3. Execute: rails generate crimagify:install

  4. Run migrations: rake db:migrate

  5. Run seeds: rake db:seed


Implementation

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

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 %>

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published