我正在尝试向用户点击下订单按钮时提供的电子邮件发送通知电子邮件,但我收到此错误
TypeError: no implicit conversion of Symbol into Integer
错误在order_controller.rb文件中,这是
class OrdersController < ApplicationController
def create
@order_form=OrderForm.new(user: User.new(order_params[:user]),cart: @cart)
if @order_form.save
notify_user
redirect_to root_path,notice:"Thank You for placing the order sir."
else
render "carts/checkout"
end
end
private
def notify_user
OrderMailer.order_confirmation(@order_form.order).deliver
end
def order_params
params.require(:order_form).permit(
user:[:name,:phone,:address,:city,:country,:postal_code,:email])
end
end
这是order_form.rb模型
class OrderForm
include ActiveModel::Model
attr_accessor :user,:order
attr_writer :cart
def save
set_password_for_user
if valid?
persist
true
else
false
end
end
def has_error?
user.errors.any?
end
private
def valid?
user.valid?
end
def persist
user.save
@order=Order.create!(user:user)
build_order_items
end
def set_password_for_user
user.password="examplepassword"
end
def build_order_items
@cart.items.each do |item|
@order.order_items.create! product_id: item.product_id, quantity: item.quantity
end
end
end
最后是我的order_mailer.rb邮件程序
class OrderMailer < ActionMailer::Base
default from: "bobbyverma946@yahoo.in"
def order_confirmation order
@order=order
mail to: order.user.email, subject: "Your order (##{order.id})"
end
end
有人可以告诉我代码有什么问题,因为我真的很困惑