1

我有一个使用 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)

我只是想弄清楚哪里出了问题。如果有人认为它可能有帮助,很高兴发布任何其他相关代码。

在此先感谢您的帮助。

4

0 回答 0