nil:NilClass (ActiveMerchant) 的未定义方法“each”
undefined method `each' for nil:NilClass (ActiveMerchant)
填写付款信息后,点击'place order'出现这个错误
NoMethodError in OrdersController#create
undefined method `each' for nil:NilClass
订单控制器
def create
@order = Order.new(order_params)
@order.add_line_items_from_cart(@cart)
credit_card = ActiveMerchant::Billing::CreditCard.new(params[:credit_card])
respond_to do |format|
if @order.save
Cart.destroy(session[:cart_id])
session[:cart_id] = nil
format.html { redirect_to category_url(Category.first), notice: 'Thank you for your order.' }
format.json { render :show, status: :created, location: @order }
else
format.html { render :new }
format.json { render json: @order.errors, status: :unprocessable_entity }
end
end
end
订购型号:
attr_accessor :card_no, :card_cvv, :expiry_date
我猜我需要在标记为 'credit_card' 的数据结构中对 :card_no、:card_cvv 和 :expiry_date 进行分组,但我不知道如何.谢谢!
编辑:
NoMethodError (undefined method `each' for nil:NilClass):
app/controllers/orders_controller.rb:32:in `new'
app/controllers/orders_controller.rb:32:in `create'
Rendering C:/RailsInstaller/Ruby2.2.0/lib/ruby/........
你需要根据你从表单发送的内容来获取参数,所以,如果你想访问它们,你必须从 order
根目录中获取参数,也就是说, card_no
将是 params[:order][:card_no]
,这样所有的人。
并且为了使用 ActiveMerchant gem 并创建一个新的 "CreditCard",您需要将您从表单收到的值传递到那里,例如:
credit_card = ActiveMerchant::Billing::CreditCard.new(
:first_name => params[:order][:first_name],
:last_name => params[:order][:last_name],
:number => params[:order][:card_cvv],
:month => params[:order][:month],
:year => Time.now.year+1, # documentation value
:verification_value => '000' # documentation value
)
填写付款信息后,点击'place order'出现这个错误
NoMethodError in OrdersController#create
undefined method `each' for nil:NilClass
订单控制器
def create
@order = Order.new(order_params)
@order.add_line_items_from_cart(@cart)
credit_card = ActiveMerchant::Billing::CreditCard.new(params[:credit_card])
respond_to do |format|
if @order.save
Cart.destroy(session[:cart_id])
session[:cart_id] = nil
format.html { redirect_to category_url(Category.first), notice: 'Thank you for your order.' }
format.json { render :show, status: :created, location: @order }
else
format.html { render :new }
format.json { render json: @order.errors, status: :unprocessable_entity }
end
end
end
订购型号:
attr_accessor :card_no, :card_cvv, :expiry_date
我猜我需要在标记为 'credit_card' 的数据结构中对 :card_no、:card_cvv 和 :expiry_date 进行分组,但我不知道如何.谢谢!
编辑:
NoMethodError (undefined method `each' for nil:NilClass):
app/controllers/orders_controller.rb:32:in `new'
app/controllers/orders_controller.rb:32:in `create'
Rendering C:/RailsInstaller/Ruby2.2.0/lib/ruby/........
你需要根据你从表单发送的内容来获取参数,所以,如果你想访问它们,你必须从 order
根目录中获取参数,也就是说, card_no
将是 params[:order][:card_no]
,这样所有的人。
并且为了使用 ActiveMerchant gem 并创建一个新的 "CreditCard",您需要将您从表单收到的值传递到那里,例如:
credit_card = ActiveMerchant::Billing::CreditCard.new(
:first_name => params[:order][:first_name],
:last_name => params[:order][:last_name],
:number => params[:order][:card_cvv],
:month => params[:order][:month],
:year => Time.now.year+1, # documentation value
:verification_value => '000' # documentation value
)