我真的很困惑,爲什麼會發生這種情況。我通過ajax調用'create'方法,它返回一個500錯誤。這是控制器:新型號參數的數量錯誤
class CallbacksController < ApplicationController
def create
new_callback = Callback.new({
date: DateTime.now,
status: 'Open',
notes: params[:callbackNotes],
action: "#{params[:callbackDate]}:#{params[:callbackTime]}",
admin: current_user.name,
set_by: current_user.name
})
customer = Customer.find params[:customer_id]
if customer.exists?
new_callback.customer = customer
new_callback.save
render json: {success: true}
end
end
end
我得到的錯誤:
wrong number of arguments (1 for 5)
突出我既new_callback = Callback.new({date: DateTime.now})
和new_callback = Callback.new
試過行new_callback = ...
。都返回類似的錯誤。我認爲這是與模型做的,但完整的跟蹤說不:
app/controllers/callbacks_controller.rb:3:in 'new'
app/controllers/callbacks_controller.rb:3:in 'create'
完全相同的線路運行完美然而,在控制檯?
請向我們展示您的回調類 – usha
根據錯誤,您的CallBack類初始化程序需要5個參數 – usha
在控制器綁定中,「Callback.superclass」返回什麼? –