【问题标题】:Rails, Heroku, Paperclip, S3 and croppingRails、Heroku、Paperclip、S3 和裁剪
【发布时间】:2012-12-30 16:45:39
【问题描述】:

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

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

为什么我的模块没有加载?

【问题讨论】:

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


    【解决方案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 上裁剪时遇到了类似的麻烦。

    【讨论】:

    • 我现在不在这个阶段!我只是在集成我的自定义缩略图处理器时遇到问题。我必须把这个模块文件放在哪里才能正确包含?我认为裁剪本身就是下一步!
    • 模块文件仅在 lib/paperclip_processors 中
    猜你喜欢
    • 1970-01-01
    • 2010-10-11
    • 2012-02-22
    • 2013-12-23
    • 1970-01-01
    • 2011-04-25
    • 2012-09-23
    • 2011-12-28
    • 2015-10-29
    相关资源
    最近更新 更多