我有一个使用Ruby on Rails(特别是rails_api)构建的应用程序,以处理来自骨干应用程序的ajax请求。
我一直在撞墙,问题是应用程序发送了ajax请求,但服务器没有正确处理,导致500错误。
以下是我的development.log文件中的代码段。
Started POST "/api/v1/students.json" for 127.0.0.1 at 2013-10-21 08:01:09 +1100
Processing by Api::V1::StudentsController#create as JSON
Parameters: {"fname"=>"Tommy", "lname"=>"", "dob"=>"", "mobile_phone"=>"", "home_phone"=>"", "work_phone"=>"", "email_address"=>"", "street_address"=>"", "suburb"=>"", "postcode"=>"", "state"=>"", "country"=>"", "licence_number"=>"", "notes"=>"", "school_or_uni"=>"", "preferred_transmission"=>""}
params
(0.2ms) BEGIN
SQL (0.7ms) INSERT INTO `students` (`created_at`, `updated_at`) VALUES ('2013-10-20 21:01:09', '2013-10-20 21:01:09')
Mysql2::Error: Field 'fname' doesn't have a default value: INSERT INTO `students` (`created_at`, `updated_at`) VALUES ('2013-10-20 21:01:09', '2013-10-20 21:01:09')
(0.3ms) ROLLBACK
Completed 500 Internal Server Error in 6ms
ActiveRecord::StatementInvalid (Mysql2::Error: Field 'fname' doesn't have a default value: INSERT INTO `students` (`created_at`, `updated_at`) VALUES ('2013-10-20 21:01:09', '2013-10-20 21:01:09')):
app/controllers/api/v1/students_controller.rb:32:in `create'
config/initializers/quite_assets.rb:7:in `call_with_quiet_assets'
Rendered /Users/jake/.rvm/gems/ruby-1.9.3-p194@noyelling-instructors-api/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_source.erb (1.5ms)
Rendered /Users/jake/.rvm/gems/ruby-1.9.3-p194@noyelling-instructors-api/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.2ms)
Rendered /Users/jake/.rvm/gems/ruby-1.9.3-p194@noyelling-instructors-api/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.9ms)
Rendered /Users/jake/.rvm/gems/ruby-1.9.3-p194@noyelling-instructors-api/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (26.6ms)
我只想弄清楚出了什么问题。很高兴发布任何其他相关代码,如果有人认为它可能有帮助。
提前感谢您的帮助。