私はカスタマー チケット (worequests) を処理する Rails アプリです。チケットには、顧客と従業員の間でやり取りされるコメントがあります。コメントには添付ファイルを含めることができます。Heroku で実行されており、PaperClip は添付ファイルを S3 に保存しています。
新しいコメントが作成され、顧客とチケットに割り当てられた従業員の両方に電子メールが送信されたとき。
CloudMailIn を使用して、顧客または従業員が新しいコメントでコメント メールに返信できるようにしています。
これまでのところ、うまくいきます!
ただし、返信メールに添付ファイルを 1 つだけ含めることを許可したいと考えています。
これは、動作中の受信メール コントローラーです。
class IncomingMailsController < ApplicationController
skip_before_filter :verify_authenticity_token
def create
Rails.logger.info params
worequest = params[:envelope][:to].split('@')[0]
contents = params[:plain].split('---')[0]
message = Comment.new(
:worequest_id => worequest,
:user_id => User.find_by_email(params[:envelope][:from]).id,
:comments => contents,
:tenant_id => 1
)
if message.save
render :text => 'Success', :status => 200
else
render :text => message.errors.full_messages, :status => 422, :content_type => Mime::TEXT.to_s
end
end
のログ結果には次がRails.logger.info params
含まれます。
"envelope"=>{"to"=>"60@mail.myapp.com", "recipients"=>{"0"=>"60@mail.myapp.com"}, "from"=>"someguy@gmail.com", "helo_domain"=>"mail-wi0-f175.google.com", "remote_ip"=>"xxx.xx.xxx.xxx", "spf"=>{"result"=>"temp_error", "domain"=>"mydomain.com"}},
"attachments"=>{"0"=>#<ActionDispatch::Http::UploadedFile:0x00000007194040 @original_filename="five guys.jpeg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"attachments[0]\"; filename=\"five guys.jpeg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20140115-5-1n2rb24>>}, "action"=>"create", "controller"=>"incoming_mails"}
attachments はハッシュで、「0」はキーの名前です。params[:attachments][‘0’]
これらのフィールドに問題なくアクセスできます。
Rails.logger.info params[:envelope][:from]
Rails.logger.info params[:envelope][:to]
Rails.logger.info params[:attachments]['0'].original_filename
Rails.logger.info params[:attachments]['0'].content_type
:attach
しかし、PaperClipファイルを設定するにはどうすればよいでしょうか。
:attach => params[:attachments]['0'].tempfile ?
:attach => params[:attachments]['0'].read ?
これは私の現在の試みです:
attach = Attachment.new(
:comment_id => 346,
:name => "Email Attachment",
:attach_file_name => params[:attachments]['0'].original_filename,
:attach_content_type => params[:attachments]['0'].content_type,
:attach => params[:attachments]['0'].path,
:tenant_id => 1
)
は:attach => params[:attachments]['0'].path,
間違っています。
これを取得する:
Paperclip::AdapterRegistry::NoHandlerError (No handler found for "/tmp/RackMultipart20140115-13-tcpvtw"):
何を使えばいいのかわからない???????
:attach => params[:attachments]['0'].read,
:attach => params[:attachments]['0'].path.to_file,
:attach => params[:attachments]['0'].path.read,
助けてくれてありがとう!