我已将我的应用程序从rails 2.3迁移到rails3,我的回形针有问题。 我看到在paperclip git上有一个rails3的分支。
所以我在Gemfile中添加了“gem'paperclip',:git =>'git://github.com/thoughtbot/paperclip.git',: branch =>'rails3'”并启动命令包安装。
安装回形针后,上传工作正常,但不是样式。我看到了一个修复它的黑客。
# in lib/paperclip/attachment.rb at line 293
def callback which #:nodoc:
# replace this line...
# instance.run_callbacks(which, @queued_for_write){|result,obj| result == false }
# with this:
instance.run_callbacks(which, @queued_for_write)
end
之后风格还可以,但我无法激活处理器。我的代码是:
has_attached_file :image,
:default_url => "/images/nopicture.jpg",
:styles => { :large => "800x600>",
:cropped => Proc.new { |instance| "#{instance.width}x#{instance.height}>" },
:crop => "300x300>" },
:processors => [:cropper]
我的处理器位于RAILS_APP / lib / paperclip_processors / cropper.rb中并包含:
module Paperclip
class Cropper < Thumbnail
def transformation_command
if crop_command and !skip_crop?
crop_command + super.sub(/ -crop \S+/, '')
else
super
end
end
def crop_command
target = @attachment.instance
trans = "";
trans << " -crop #{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}" if target.cropping?
trans << " -resize \"#{target.width}x#{target.height}\""
trans
end
def skip_crop?
["800x600>", "300x300>"].include?(@target_geometry.to_s)
end
end
end
我的问题是我收到此错误消息:未初始化的常量Paperclip :: Cropper 未加载裁剪的处理器。
有人有想法解决这个问题吗?
有关信息,我的应用程序在rails 2.3.4上运行良好。
答案 0 :(得分:5)
我有同样的问题。好像回形针处理器没有加载到rails 3.直到有人修复它,我才解决了在/ config / initializers中移动cropper.rb文件的问题
答案 1 :(得分:2)
重启服务器,为我工作:)
答案 2 :(得分:1)
我也得到了“未初始化的常量Paperclip :: Cropper”异常。 但是您可以将cropper.rb移动到paperclip lib目录并添加require'paperclip / cropper.rb'。它适合我,但我使用捆绑器,所以它看起来很丑......
答案 3 :(得分:1)
在你的Photo.rb课程中,或者你曾经需要'... / cropper.rb'的课程中,你必须将项目的根目录放在路径中:
require "#{config.root}/lib/paperclip_processors/cropper.rb" # required to make cropping work.
以前只需要“lib /...”
答案 4 :(得分:0)
我有同样的问题。我正在使用此存储库中的paperclip gem:
gem "paperclip", :git => "git://github.com/JasonKing/paperclip.git", :branch => "rails3"
我还得到了“未初始化的常量Paperclip :: Cropper”。重启服务器不起作用!
答案 5 :(得分:0)
是的,将Paperclip安装为插件并且可以正常工作
答案 6 :(得分:0)
我建议你使用carrierwave代替回形针,快速而简单https://github.com/jnicklas/carrierwave