Reputation: 2409
I am really confused as to why this is happening. I'm calling the 'create' method via ajax and it returns a 500 error. This is the controller:
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
I get the error:
wrong number of arguments (1 for 5)
highlighting the line new_callback = ...
I've tried it with both new_callback = Callback.new({date: DateTime.now})
and new_callback = Callback.new
. Both return similar errors. I thought it was to do with the model but the full trace says not:
app/controllers/callbacks_controller.rb:3:in 'new'
app/controllers/callbacks_controller.rb:3:in 'create'
The exact same line works perfect in the console however?
Upvotes: 0
Views: 393
Reputation: 1692
the Callback is a rails class inside the ActiveSupport package, ActiveSupport::Callbacks::Callback. and the constructor for it is like this new(chain, filter, kind, options, klass). Rename you model name will solve it.
Upvotes: 4