【问题标题】:Carrierwave remote attachment url not working on creationCarrierwave 远程附件 url 无法创建
【发布时间】:2017-09-04 04:29:15
【问题描述】:

我的 Ruby on Rails 项目中有一个名为 ApplicationAttachment 的模型。

我还在我的 s3 存储桶上上传了文件。当我尝试将图像上传到我的模型时,我没有收到错误,但附件是 nil 并且 remote_attachment_url 没有保存文件。不知道是什么问题。

我的代码是这样的

ApplicationAttachment.create!(remote_attachment_url: "http://www.jqueryscript.net/images/jQuery-Plugin-For-Fullscreen-Image-Viewer-Chroma-Gallery.jpg")

这不会返回任何错误,但不会保存图像。

class ApplicationAttachment < ActiveRecord::Base
  mount_uploader :attachment, DeveloperReferralAttachmentUploader
  attr_accessible :id, :attachment, :remote_attachment_url, :created_at, :updated_at
end

class DeveloperReferralAttachmentUploader < CarrierWave::Uploader::Base
  storage :file
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  def extension_white_list
    %w(pdf jpg jpeg gif png)
  end
end

如何确保 remote_image_url 在通过 Carrierwave 创建时保存。

谢谢

【问题讨论】:

    标签: ruby-on-rails carrierwave


    【解决方案1】:

    我认为您可能希望明确保存附件,而不是使用 create

    aa = ApplicationAttachment.new(
           remote_attachment_url: "http://www.jqueryscript.net/images/jQuery-Plugin-For-Fullscreen-Image-Viewer-Chroma-Gallery.jpg"
         )
    aa.save
    

    【讨论】:

      猜你喜欢
      • 2017-06-15
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 2013-05-30
      • 2017-03-03
      • 1970-01-01
      • 2015-02-08
      • 2019-02-24
      相关资源
      最近更新 更多