新手问题 carrierwave 使用 github 的版本不能搭配 aliyun 插件

u1450154824 · 2016年05月10日 · 最后由 u1450154824 回复于 2016年05月11日 · 2252 次阅读

@huacnlee 因为想做多图片上传,看到帖子说 carrierwave 原生支持,但是需要指定github 主分支. 如下

gem 'carrierwave', github: 'carrierwaveuploader/carrierwave' 并且 model 里是 mount_uploaders :images, LocalUploader 不是 mount_uploader 如果,不用github的版本,会 找不到mount_uploaders.

我试了一下,本地图片上传多图片可以成功. 但是如果使用了 gem 'carrierwave-aliyun' 会出现,

$ rails s
/home/lux/.rvm/gems/ruby-2.2.4/gems/carrierwave-aliyun-0.4.3/lib/carrierwave-aliyun.rb:2:in `require': cannot load such file -- carrierwave/processing/mime_types (LoadError)
        from /home/lux/.rvm/gems/ruby-2.2.4/gems/carrierwave-aliyun-0.4.3/lib/carrierwave-aliyun.rb:2:in `<top (required)>'
        from /home/lux/.rvm/gems/ruby-2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:77:in `require'
        from /home/lux/.rvm/gems/ruby-2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:77:in `block (2 levels) in require'
        from /home/lux/.rvm/gems/ruby-2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
        from /home/lux/.rvm/gems/ruby-2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
        from /home/lux/.rvm/gems/ruby-2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
        from /home/lux/.rvm/gems/ruby-2.2.4/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
        from /home/lux/.rvm/gems/ruby-2.2.4/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
        from /home/lux/dowedo/dowedo-bill/config/application.rb:7:in `<top (required)>'
        from /home/lux/.rvm/gems/ruby-2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:78:in `require'
        from /home/lux/.rvm/gems/ruby-2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:78:in `block in server'
        from /home/lux/.rvm/gems/ruby-2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap'
        from /home/lux/.rvm/gems/ruby-2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server'
        from /home/lux/.rvm/gems/ruby-2.2.4/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
        from /home/lux/.rvm/gems/ruby-2.2.4/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

共收到 7 条回复

这样改了之后,好像是可以了?

require 'carrierwave/storage/aliyun'
require 'carrierwave/processing/mini_magick'
require 'carrierwave/aliyun/configuration'

CarrierWave.configure do |config|
  config.storage_engines.merge!({ aliyun: 'CarrierWave::Storage::Aliyun' })
end

CarrierWave::Uploader::Base.send(:include, CarrierWave::Aliyun::Configuration)
CarrierWave::Uploader::Base.send(:include, CarrierWave::MiniMagick)
# CarrierWave::Uploader::Base.send(:process, :set_content_type)


加了 gem gem 'mini_magick'

我来试试

#1楼 @u1450154824 试试 0.4.4 版本,刚刚发布了。

我暂时不在 carrierwave 的高版本里面应用 MimeType,不知道行不行,有待测试。 官方那个去掉那个文件的 PR 里面没讲替代方案

#3楼 @huacnlee 好的,效率好高,手动赞

楼主,

你的头像太撩人了,不如换成真人头像吧。

Thank you.

😄

#6楼 @xiaoronglv 所以你怎么又能确定之前的不是我真人,哈哈

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册