【问题标题】:CarrierWave not work with CloudinaryCarrierWave 不适用于 Cloudinary
【发布时间】:2018-05-19 04:37:07
【问题描述】:

在 user.rb 中

类用户

在picture_uploader.rb中

类 PictureUploader <:uploader::base>

包括 Cloudinary::CarrierWave

存储:文件

# 对于要挂载的上传者来说,这是一个合理的默认设置:

定义存储目录 “上传/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}” 结束

结束

在环境.rb中

require_relative '应用程序'

初始化 Rails 应用程序

Rails.application.initialize!

需要'carrierwave/orm/activerecord'

在_form.html.erb中

<%= form.label :picture %>

<%= form.file_field :picture, id: :user_picture %>

迁移中

类 CreateUsers

定义改变

create_table :用户做|t|

  t.string :email

  t.string :picture

  t.timestamps

end

结束

结束

最后 User.picture_url 是 Cloudinary 上的一个 url,但这个 url 中没有上传任何图片。

如果我输入 rails c 就可以了 Cloudinary::Uploader.upload('/home/my_image.jpg')

【问题讨论】:

    标签: ruby-on-rails carrierwave image-uploading cloudinary


    【解决方案1】:

    The Cloudinary 的热线回答者:

    “请注释掉 /app/uploader/pictures_uploader.rb 中的第 10 行和第 15-17 行”

    # 存储:文件

    # def store_dir # "上传/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" #结束

    它有效。

    【讨论】:

      【解决方案2】:

      你的app/assets/javascript/application.jsadd 有吗

      //= require cloudinary/jquery.cloudinary
      

      app/views/layouts/application.html.erb

          <%= yield(:after_js) %>
          <%= javascript_include_tag "application", 'data-turbolinks-track' => true %>
          <%= cloudinary_js_config %>
      

      application.yml(你可以在你的云设置中找到你的)

      CLOUDINARY_URL: "cloudinary:/`/768932967533141:wF2ZZZrTuQ6R2Ynf_1mH3zk@dtrucdxbug"
      #this a fake url ;-)
      

      你的问题更多在于你的 show.html.erb :)

        <%= cl_image_tag(@user.picture.path, :secure => true,
                          :width => 100, :height => 150, :crop => :fill) %>
      

      这里的设置只是一个例子,但你需要@user.picture.path来显示你的图片:)

      更多信息在这里https://cloudinary.com/documentation/rails_image_manipulation

      【讨论】:

        猜你喜欢
        • 2013-06-17
        • 2015-10-22
        • 1970-01-01
        • 2017-06-30
        • 1970-01-01
        • 1970-01-01
        • 2012-11-11
        • 1970-01-01
        • 2015-12-06
        相关资源
        最近更新 更多