Rails3 和回形针 [英] Rails3 and Paperclip
问题描述
我已将我的应用程序从 rails 2.3 迁移到 rails3,但我遇到了回形针问题.我看到在回形针 git 上有一个 rails3 的分支.
I have migrated my application from rails 2.3 to rails3 and i have a problem with paperclip. I saw there was a branch for rails3 on paperclip git.
所以我在 Gemfile 中添加了gem 'paperclip', :git => 'git://github.com/thoughtbot/paperclip.git', :branch => 'rails3'"并启动命令包安装.
So I added "gem 'paperclip', :git => 'git://github.com/thoughtbot/paperclip.git', :branch => 'rails3'" into the Gemfile and launch the command bundle install.
安装回形针后,上传工作正常,但样式不行.我看到了一个黑客来修复它.
Once paperclip installed, the upload worked fine but not the styles. I saw a hack to fix it.
# 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
此后样式正常,但我无法激活处理器.我的代码是:
The styles are ok after that, but i'm not able to active the processor. My code is :
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 并包含:
My processor is located in RAILS_APP/lib/paperclip_processors/cropper.rb and contains :
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未加载裁剪的处理器.
My problem is that i got this error message : uninitialized constant Paperclip::Cropper The cropped processor is not loaded.
有人想解决这个问题吗?
Is anybody has an idea to fix that ?
有关信息,我的应用程序在 rails 2.3.4 上运行良好.
For information my application works fine on rails 2.3.4.
推荐答案
我有同样的问题.似乎回形针处理器没有加载到 rails 3 中.在有人修复它之前,我解决了在/config/initializers 中移动cropper.rb 文件的问题
I have the same problem. Seems like paperclip processors are not loaded in rails 3. Until someone fix it, I hacked the problem moving the cropper.rb file inside /config/initializers
这篇关于Rails3 和回形针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!