これは私の _line_items.text.erb ファイルにあります:
<%= sprintf("%2d x %s", line_item.quantity,
truncate(line_item.product.title, length: 50)) %>
注文.yml
one:
name: Dave Thomas
address: MyText
email: dave@example.org
pay_type: Check
line_items.yml
one:
product: ruby
cart_id: 1
order: one
two:
product_id: 1
cart_id: 1
order: one
製品.yml
ruby:
title: Programming Ruby 1.9
description:
Ruby is the fastest growing and most exciting dynamic language out there.
If you need to get working programsdelivered fast, you should add Ruby to your toolbox.
price: 49.50
image_url: ruby.png
これはすべて正しいようです。
実際のテストは次のとおりです。
class OrderNotifierTest < ActionMailer::TestCase
test "received" do
mail = OrderNotifier.received(orders(:one))
assert_equal "Pragmatic Store Order Confirmation", mail.subject
assert_equal ["dave@example.org"], mail.to
assert_equal ["depot@example.com"], mail.from
assert_match /1 x Programming Ruby 1.9/, mail.body.encoded
end
ActionView::Template::Error: undefined method 'title' for nil:NilClass
エラーを探す他の場所についてのアイデアはありますか?
アップデート:
class LineItem < ActiveRecord::Base
attr_accessible :cart_id, :product_id, :quantity, :order_id, :product, :cart, :price
belongs_to :order
belongs_to :cart
belongs_to :product
def total_price
self.price * self.quantity
end
end