0

カスタムクラスでCarrierWaveのcurrent_pathを呼び出すことができません。CarrierWaveのNoMethodError 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コールで発生していますが、その理由はわかりません。レールコンソールでは同じコマンドがうまく動作しますが、rakeタスクで実行するときにNoMethodError(上記)で失敗します。 current_pathの代わりにファイルへのパスを取得する方法(CarrierWaveを使用してアップロードした場合)あなたの時間のためのThx!

更新 あなたの答えはThxです。 letter.template.present? - true

letter.template.attachment.present? -true

letter.template.attachment.methods.respond_to(:CURRENT_PATH) - 偽

しかしletter.template.attachment.methods(あり:CURRENT_PATH)?

:キャッシュ!,: cache_stored_file、:cache_stored_file、:sanitized_file、:モデル、:マウント済み、:to_s、:長さ、:サイズ、:パス、:read、:content_type、:空白?、:current_path

答えて

0

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も上書きされているようです。try - トレースはsend_letterのように見えますか?

+0

更新された質問 – likitung