我正在进行ajax通话。当我按发送时,我想发送一封电子邮件,但我甚至没有在我的控制器操作中进入任何东西。这就好像ajax调用搞乱了。我在ajax调用中发送了三个字符串。
老实说,我不知道出了什么问题,我对它完全感到困惑。
编辑:经过一些测试,我很肯定在从我的AJAX调用到我的服务器的过程中发生了错误。我不明白为什么。
的Ajax:
send: function() {
var data = $('.sendEmail').serializeJSON();
$.ajax({
url: '/emails/send',
type: 'POST',
data: data,
success: function(res) {
console.log("oh yes!");
},
error: function(what) {
console.log(what);
}
});
}
路线:
post 'emails/send', :to => "emails#send"
控制器操作:
def send
email = params['email']
Mailer.email(email['recipients'], current_user.email, email['subject'], email['content']).deliver!
render :json => email
end
梅勒方法:
def email(recipient, sender, subject, content)
mail(:to => recipient, :from => sender, :body => content, :content_type => "text/html", :subject => subject)
end
错误:
Started POST "/emails/send" for 127.0.0.1 at 2013-11-30 06:06:40 -0600
Processing by EmailsController#send as */*
Parameters: {"email"=>{"recipients"=>"myemail@gmail.com", "subject"=>"wowowowow", "content"=>"omgomgomgomg"}}
Completed 500 Internal Server Error in 1ms
ArgumentError - wrong number of arguments (2 for 0):
activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.13) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.13) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:18:in `process_action'.......