2013-01-16 95 views
0

对于我的应用程序,我需要裁剪图像的功能。 我跟着railscast http://railscasts.com/episodes/182-cropping-imagesRails,Heroku,回形针,S3和裁剪

Aaaall在我的本地机器上正常工作。我有我的Owm回形针处理器,它从Thumbnail处理器扩展而来。该处理器被保存在LIB/paperclip_processors/cropper.rb

module Paperclip 
    class Cropper < Thumbnail 

    def transformation_command 
     if crop_command 
     cmd = crop_command + super.join(" ").sub(/ -crop \S+/, '') 
     cmd.split(" ") 
     else 
     super 
     end 
    end 

    def crop_command 
     target = @attachment.instance 
     if target.cropping? 
     " -crop \"#{target.crop_w.to_i}x#{target.crop_h.to_i}+#{target.crop_x.to_i}+#{target.crop_y.to_i}\" " 
     end 
    end 
    end 
end 

在我的本地机器它采用这款处理器的裁剪。在heroku上,似乎这个模块完全被忽略了。

是的,我搜索了约6个小时的解决方案...

1.

#application.rb 
config.autoload_paths += %w(#{config.root}/lib)  
#or 
config.autoload_paths += Dir["#{config.root}/lib/**/"] 
#or 
config.autoload_paths += Dir["#{config.root}/lib/paperclip_processors/cropper.rb"] 

#all not working 

2.

#initializers/includes.rb 
require "cropper" 

#or 

Dir[Rails.root + 'lib/**/*.rb'].each do |file| 
    require file 
end 

凭啥我的模块没有加载?

回答

0

您可能想检查条件是否正在调用。

if target.cropping? 
     " -crop \"#{target.crop_w.to_i}x#{target.crop_h.to_i}+#{target.crop_x.to_i}+ #{target.crop_y.to_i}\" " 
    end 

几天前,我在Heroku上裁剪出类似的麻烦。

+0

我现在不在这一点!我只是有问题来集成我的自定义缩略图处理器。我在哪里必须把这个模块文件是正确的?我认为种植本身就是下一步! –

+1

模块文件只进入lib/paperclip_processors –