【问题标题】:NoMethodError for CarrierWave current_pathCarrierWave current_path 的 NoMethodError
【发布时间】:2017-10-17 14:48:15
【问题描述】:

我无法在我的自定义类中调用 CarrierWave current_path。

NoMethodError: private method `try' called for #<CarrierWave::SanitizedFile:0x007fadf259fbf8>



def send_letter(letter)
   data = {}
   data[:attachment]   = File.new("#{letter.template.attachment.current_path}", 'rb')
end

它发生在 letter.template.attachment.current_path 调用中,我不明白为什么。在 Rails 控制台中,相同的命令效果很好......但是当我尝试使用 rake 任务运行它时,它会因 NoMethodError(上图)而失败。如何获取文件的路径而不是 current_path(如果它是使用 CarrierWave 上传的)。谢谢你的时间!

更新 谢谢你的回答。 letter.template.present? - 真的

letter.template.attachment.present? -真

letter.template.attachment.methods.respond_to?(:current_path‌​) - false

但是 letter.template.attachment.methods(有 :current_path)

:cache!, :cache_name, :retrieve_from_cache!, :cache_stored_file!, :sanitized_file, :model, :mounted_as, :to_s, :length, :size, :path, :read, :content_type, :identifier, :blank ?, :current_path

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4 ruby-on-rails-5 carrierwave


    【解决方案1】:

    NoMethodError 表示,嗯,没有attachment#current_path

    letter.template.present?,是letter.template.attachment.present?,是letter.template.attachment.methods.respond_to?(:current_path)

    点击letter.template.attachment.methods,查看letter.template.attachment 可用的方法。

    看起来 CarrierWave 也覆盖了 trysend_letter 的跟踪是什么样的?

    【讨论】:

    • 更新了我的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多