【发布时间】: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