ruby-on-rails - 发送带有附件名称操作 Mailer Ruby on Rails 的电子邮件
问题描述
我有一些来自哈希的参数,我想通过电子邮件发送。对于我的附件文件(发票)的名称,我想要我的商店名称和有关此发票的信息。当我运行我的测试时,我收到 9 封电子邮件,而不是 3 封,因为我的 .each 但我不知道该怎么做,有人可以帮助我只收到 3 封带有名称和 shop 变量的文档。
这是我的控制器:
if(params.dig('connection')!= nil)
#GET ALL MY DOCUMENTS
documents = params.dig('connection', 'subscriptions').each_with_object([]) { |x, arr| x['documents'].each { |d| arr << d['url'] } }.to_s
#GET THE NAME OF THE SHOP
shop = params.dig('connection','connector', 'name').to_s
#GET ALL THE INFORMATIONS
names = params.dig('connection', 'subscriptions').each_with_object([]) { |x, arr| x['documents'].each { |d| arr << d['name'] } }.to_s
full_name = JSON.parse(names)
full_name.each do |name| puts "CHAQUE NAME " + name
array_docs = JSON.parse(documents)
bearer_token = request.headers["Authorization"]
array_docs.each do |doc|
decoded_doc = URI.parse(URI.escape(doc)).to_s
tmp_file = Tempfile.new(['invoices', '.pdf'])
tmp_file.binmode
open(decoded_doc, "Authorization" => bearer_token) do |url_file|
tmp_file.write(url_file.read)
tmp_file.rewind
tmp_file.read
attached_file = tmp_file.path
attachment = Array.new
attachment = {filename: shop+".pdf", file: attached_file}
InvoiceMailer.send_invoice(attachment).deliver
end
end
end
end
我可以做类似的事情:
documents = params.dig('connection', 'subscriptions').each_with_object([]) { |x, arr| x['documents'].each { |d| arr << d['url'], |n| arr << n['name'] } }.to_s
解决方案
推荐阅读
- ios - iPhone XR 上的状态栏文本颜色不同
- reactjs - 大量组件正在更新,但状态没有任何相关变化
- ffmpeg - ffmpeg avcodec_send_packet/avcodec_receive_frame 内存泄漏
- animation - 如何在 SkiaSharp 中获得流畅的动画
- html - 将输入文本放入图像中并使其具有响应性(css)
- ios - 将 Firebase(GoogleService-Info.plist 和 API 密钥)迁移到 iOS App Store 上的生产环境?
- visual-studio - Visual Studio 2017 Xamarin Designer 不显示内容,即使它以前有
- java - 在改造2中使用带有对象数组的json
- javascript - 为什么我的 React 站点在注册或登录后不会重定向到主页?
- javascript - 如何一个接一个地访问网址列表?