【问题标题】:Rails 3 Dragonfly uid of attachment is correct but the file iself is nil附件的Rails 3 Dragonfly uid是正确的,但文件本身为零
【发布时间】:2012-07-21 05:00:52
【问题描述】:

我使用 Dragonfly 和 Amazon s3 来上传图片。由于某种原因,当我上传图片时,它保存到亚马逊上的正确文件夹,并且uid是正确的路径,但它没有显示出来!

即使user.avatar_uid 是正确的,每次我调用user.avatar 时它都是零。如何使用user.avatar.remote_url 正确显示图像?

class User < ActiveRecord::Base

  image_accessor :avatar do
    storage_path { |file| 
      "#{self[:id]}/avatar/pic#{rand(1000)}.#{file.format.to_s.downcase}" 
    }
    after_assign { |a| 
      self.avatar = a.jpg.thumb('300x300#n') if (VALID_PHOTO_TYPES.include? self.avatar.format)
    }
  end  

  attr_accessible :avatar_url, :retained_avatar, :avatar
  attr_reader :id, :avatar_uid

【问题讨论】:

  • 这让我困惑了几个小时,所以我希望没有其他人必须通过自己猜测和检查来弄清楚这一点。

标签: ruby-on-rails ruby-on-rails-3 amazon-s3 dragonfly-gem


【解决方案1】:

问题是 attr_reader、attr_writer、attr_accessible 中的任何一个中的 :avatar_uid

如果你的模型中有这个,它就会坏掉。假设任何带有 Dragonfly 的模型都不存在 *_uid,并且只使用 user.avatar。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-08
    • 1970-01-01
    • 2019-02-24
    • 2019-10-30
    • 2020-03-01
    • 1970-01-01
    • 2014-10-13
    相关资源
    最近更新 更多