Rails,Heroku,Paperclip,S3和裁剪

时间:2013-01-16 11:19:30

标签: ruby-on-rails ruby-on-rails-3 heroku amazon-s3 paperclip

对于我的应用程序,我需要一个图像裁剪功能。 我跟着railscast http://railscasts.com/episodes/182-cropping-images

Aaaall在我的本地机器上工作正常。我有自己的自动回形针处理器,它从缩略图处理器扩展而来。该处理器存储在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

为什么我的模块不加载?

1 个答案:

答案 0 :(得分:1)

您可能想要检查是否已调用该条件。

    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上出现了类似的问题。