开发者

Best way to send mail with attachments uploaded by form in Ruby on Rails

what's the best way to upload an attachment by form and send an email? The attachment doesn't need to be stored on the server.

I found a sexy jQuery开发者_如何学编程 uploader: https://github.com/blueimp/jQuery-File-Upload/ and a guide for RoR3 https://github.com/blueimp/jQuery-File-Upload/wiki/jQuery-File-Upload-for-Rails-3

but how to implement without saving as file on the server?

Or is there an other easy way?

Thanks andi


The above code uses paperclip, which by default saves the file into your public directory when you save the associated model. You might be able to use the queued_for_write method to access the file before calling save (and avoid calling save).

Alternatively: Since file uploads and email sends can both be slow, you might want to separate out the two so that your app feels more speedy for your users.

1) Use paperclip to save the file. Then end this request and let the user know it's queued up.

2) Have a background process or delayed job go through your model, find the file, email it, then delete it (and update/delete the model as necessary).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜