这是在我的 _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