私はアクションメーラーを使用して、チェックアウト時にウェブサイト管理者にメールを送信しようとしています。新しい料金が作成されたが完全なメッセージを送信していないときに電子メールが送信されます。ショッピングカートの表示ページの表示をメーラーにどのように伝えますか?Rails Action Mailer:表示ページでメールを送信するHTML
ここはメーラーのhtmlです。私はこの@order_items行が間違っていると確信していますが、私はショッピングカートの表示ページからHTMLをレンダリングするようにメーラーに指示する方法がわかりません。現在、電子メールは送信されますが、新しいオーダー明細が送信されます。
order_email.html.erb:
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>You have a new order </h1>
<p>
<%= @order_items %> <br>
</p>
</body>
</html>
これはshopping_cart部分リストORDER_ITEMSのすべての私のショッピングカートのショーのページです。 カート/ show.html.erb:
<div class="shopping-cart">
<%= render "shopping_cart" %>
<h4 class="text-right">Subtotal: <span style="color: green"><%= number_to_currency current_order.subtotal %></span></h4>
<h4 class="text-right">Shipping: <span style="color: green"><%= number_to_currency current_order.shipping %></span></h4>
<h4 class="text-right">Order Total: <span style="color: green"><%= number_to_currency current_order.total %></span></h4>
<%= link_to 'Checkout', new_charge_path %>>
</div>
料コントローラ クラスChargesController < ApplicationControllerに デフ新しいここで終わり
end
def create
# Amount in cents
@amount = (current_order.total * 100).to_i
OrderMailer.order_email(@order_items).deliver_now
customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:source => params[:stripeToken]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => @amount,
:description => 'Order',
:currency => 'usd'
)
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
は私のメーラーです:
class OrderMailer < ApplicationMailer
add_template_helper(OrderItemsHelper)
default from: "[email protected]"
def order_email(order_items)
@order_items = order_items
mail(to: "[email protected]", subject: "New Order")
end
end
は、ここで私は取得していますエラーです:
OrderMailer#order_email: processed outbound mail in 46.1ms
Completed 500 Internal Server Error in 138ms (ActiveRecord: 2.5ms)
ActionView::Template::Error (Missing partial order_mailer/_shopping_cart, application_mailer/_shopping_cart with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
* "/home/ubuntu/workspace/app/views"
* "/usr/local/rvm/gems/ruby-2.3.0/gems/devise-4.2.0/app/views"
):
1:
2: <div class="shopping-cart">
3:
4: <%= render "shopping_cart" %>
5: <h4 class="text-right">Subtotal: <span style="color: green"><%= number_to_currency current_order.subtotal %></span></h4>
6: <h4 class="text-right">Shipping: <span style="color: green"><%= number_to_currency current_order.shipping %></span></h4>
7: <h4 class="text-right">Order Total: <span style="color: green"><%= number_to_currency current_order.total %></span></h4>
app/views/carts/show.html.erb:4:in `_app_views_carts_show_html_erb__237194399509057886_70276459395980'
app/views/order_mailer/order_email.html.erb:7:in `_app_views_order_mailer_order_email_html_erb___3173067988541617898_70276461477720'
app/mailers/order_mailer.rb:11:in `order_email'
app/controllers/charges_controller.rb:10:in `create'
Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_source.erb (32.5ms)
Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (7.1ms)
Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.1ms)
Rendered /usr/local/rvm/gems/ruby-2.3.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (140.8ms)
を動作するかどうか、私に教えてください私は、<%=レンダリング(テンプレート:「カート/ショー」)%>を試してみましたが、私は部分的order_mailerが見つからないというエラーを取得しています/私のショッピングカートのショーのページを_shopping_cart持っています_shopping_cartの部分。私はコードに追加すべき何かがあるので、部分も見つけられるでしょうか? – Kris
ええ、ほとんどの場合、レンダリングメソッドで明示的に表現する方が常に良いです。あなたは、<%= render "shopping_cart"%> "から" <%=レンダリング "カート/ shopping_cart"%> ' – oreoluwa
Upvoteに変更し、問題が解決したら答えを受け入れることで修正できるはずです。 – oreoluwa