您好我正在阅读Agile Web Development with Rails第4版Book但我在'任务H:发送邮件'中收到错误
我有邮件 order_notifier.rb
class OrderNotifier < ActionMailer::Base
default :from => "name@email.tld"
def received
@order = order
mail(:to => order.email, :subject => 'Pragmatic Store Order Confirmation')
end
def shipped
@order = order
mail(:to => order.email, :subject => 'Pragmatic Store Order Shipped')
end
end
我有模板 / views / order_notifier / 已收到 .text.erb和已发货 .text.erb
Dear <%= @order.name %>
Thank you for your recent order from The Pragmatic Store.
You ordered the following items:
<%= render @order.line_items %>
We'll send you a separate e-mail when your order ships.
我从 OrdersController 运行它 我不确定是否使用current_cart或@cart但我认为这无关紧要
def create
@order = Order.new(params[:order])
@order.add_line_items_from_cart(current_cart)
#@order.add_line_items_from_cart(@cart)
respond_to do |format|
if @order.save
Cart.destroy(session[:cart_id])
session[:cart_id] = nil
OrderNotifier.received(@order).deliver
错误我告诉我收到的方法有一个多于它需要的参数(@order)但那就是它在书中的写法..错误:
ArgumentError in OrdersController#create
wrong number of arguments (1 for 0)
错误在哪里?谢谢。
答案 0 :(得分:1)
错误是OrderNotifier中的received
方法没有参数,但是你的控制器正在传递一个参数。您应该修改通知程序以使用一个参数order
。
另外,我不建议阅读使用Rails的敏捷Web开发。