2
我正在使用Pragmatic Agile Rails開發書練習ROR4。其中有一部分關於通過ActionMailer發送電子郵件。雖然我能夠發送電子郵件,我無法刪除eppended Rails的對象,如下圖所示,在突出區域: (
LineItem
是一個模型,用於存儲量的Product
買受人放入Cart
)爲什麼Rail Objects通過ActionMailer發送的電子郵件中出現
這些都是我的文件的內容:
// order_notifier.rb = my email sender model
class OrderNotifier < ActionMailer::Base
default from: "[email protected]"
def received(order)
@order=order
mail to: @order.email, subject: 'Pragmatic Store Order Confirmation'
end
def shipped
mail to: "[email protected]"
end
end
// recieved.html.erb = the mail that will be sent
<h3>PragmaticOrderShipped</h3>
<p>This is just to let you know that we've shipped your recent order:</p>
<table>
<tr>
<th>Description</th>
<th>Qty</th>
</tr>
<%[email protected]_items.each do |o_li|%>
<tr>
<td><%=Product.find(o_li.product_id).title%></td>
<td><%=o_li.quantity%></td>
</tr>
<%end%>
</table>
有人能告訴我,爲什麼是LineItem
東西顯示在最後的電子郵件嗎?
也可以改變'<%= Product.find(o_li.product_id).title僞%>''到<%= o_li.product.title%>'如果你想一些代碼重用的因素。 – 2014-09-23 13:50:41
@DanFairaizl - thankx。那就是訣竅。 – zhirzh 2014-09-23 14:22:34
@NitinVerma - 是的。我在提問產品belongs_to line_items的時候也忘了。傻我。 – zhirzh 2014-09-23 14:25:29