我真的很困惑为什么会这样。我通过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 = ...
行
我已经使用new_callback = Callback.new({date: DateTime.now})
和new_callback = Callback.new
进行了尝试。两者都返回类似错误。我认为这与模型有关,但完整的痕迹不是:
app/controllers/callbacks_controller.rb:3:in 'new'
app/controllers/callbacks_controller.rb:3:in 'create'
然而,完全相同的行在控制台中是完美的吗?
答案 0 :(得分:4)
Callback是ActiveSupport包中的rails类,ActiveSupport :: Callbacks :: Callback。它的构造函数就像这个新的(chain,filter,kind,options,klass)。重命名模型名称将解决它。