模型new的参数数量错误

时间:2013-12-11 14:57:22

标签: ruby-on-rails

我真的很困惑为什么会这样。我通过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'

然而,完全相同的行在控制台中是完美的吗?

1 个答案:

答案 0 :(得分:4)

Callback是ActiveSupport包中的rails类,ActiveSupport :: Callbacks :: Callback。它的构造函数就像这个新的(chain,filter,kind,options,klass)。重命名模型名称将解决它。