ruby-on-rails – Rails3和Paperclip

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Rails3和Paperclip前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已将我的应用程序从rails 2.3迁移到rails3,我的回形针有问题.
我看到在paperclip git上有一个rails3的分支.

所以我在Gemfile中添加了“gem’paperclip’,:git =>’git://github.com/thoughtbot/paperclip.git’,: branch =>’rails3’”并启动命令bundle install.

一旦安装了回形针,上传工作正常但不是样式.我看到了修复它的黑客攻击.

  1. # in lib/paperclip/attachment.rb at line 293
  2. def callback which #:nodoc:
  3. # replace this line...
  4. # instance.run_callbacks(which,@queued_for_write){|result,obj| result == false }
  5. # with this:
  6. instance.run_callbacks(which,@queued_for_write)
  7. end

之后风格还可以,但我无法激活处理器.我的代码是:

  1. 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中,包含:

  1. module Paperclip
  2. class Cropper < Thumbnail
  3. def transformation_command
  4. if crop_command and !skip_crop?
  5. crop_command + super.sub(/ -crop \S+/,'')
  6. else
  7. super
  8. end
  9. end
  10.  
  11. def crop_command
  12. target = @attachment.instance
  13. trans = "";
  14. trans << " -crop #{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}" if target.cropping?
  15. trans << " -resize \"#{target.width}x#{target.height}\""
  16. trans
  17. end
  18.  
  19. def skip_crop?
  20. ["800x600>","300x300>"].include?(@target_geometry.to_s)
  21. end
  22. end
  23. end

我的问题是我收到此错误消息:未初始化的常量Paperclip :: Cropper
未加载裁剪的处理器.

有人有想法解决这个问题吗?

有关信息,我的应用程序在rails 2.3.4上正常工作.

解决方法

我也有同样的问题.好像回形针处理器没有加载到rails 3.直到有人修复它,我破解了在/ config / initializers中移动cropper.rb文件的问题

猜你在找的Ruby相关文章