1
複数のメールを複数のブランドに送信しようとしています。私はメール受信者の電子メールを変更しながらこの複数回実行するループを作成しようとしましたが、最後のメール要求にのみ送信します。これをどうやって解決するのだろうか?ここに私の現在のコードは次のとおりです。複数のメールを送信していますか?
@user_products.each do |p|
@brands << p.brand
end
count = 0
@brands = @brands.uniq
while count < @brands.count
debugger
@brand = @brands[count]
mail(to: @brands[count].email, subject: 'A purchase has been made!')
count += 1
end
私のhtmlコードは、特定のブランドで作られた上で製品を得るために:私はループを実行し、それが走ったとして私の電子メールのためのデバッガがある
<body style="margin-left: auto; margin-right: auto; background-color: #d55d5d; width: 75%;">
<div align="center">
<img src="http://localhost:3000/assets/motobanner-d2fde8a6e30060905a6f72b0c8128d222a7596e690a7a4c648e5e81109bf4600.jpg" style="margin-top: 0% ;width: 75%; height: 240px;" ></img>
</div>
<div align="center">
<h2>Hello, <%= @brand.name %>!</h2>
<p style="font-size: 1.2em;">There has been a purchase of the following items:</p>
<% @user_products.each do |item| %>
<div align="center"> <%= image_tag "http://localhost:3000/#{item.picture.url}", alt: item.product_name if item.picture && item.brand_id == @brand.id %><br /></div>
<b><%= "Product name:" if item.brand_id == @brand.id %></b> <%= item.product_name if item.brand_id == @brand.id %>
<b><%= "Product description:" if item.brand_id == @brand.id %></b><br /> <p class="product-description"><%= item.product_description if item.brand_id == @brand.id %></p>
<b><%= "Product price:" if item.brand_id == @brand.id %></b> <%= "£" + item.product_price.to_s if item.brand_id == @brand.id %>
<% end %>
</body>
なぜなら、なぜそれがうまくいかないのか理解できない理由です。
メールオブジェクトはsendメソッドを持っています。 あなたが効果的にすべてのメールを構築していると思いますが、レールが最後のものを送信しますそれは最後に返されます。 – Sidewinder94
ああ私が見るこのアクションを実行するためのより良い方法がありますか? –