Rails 5.2.2.1
我想您不明白我在说什么,我把日志记录下来并加以解释。
[INFO]2019-04-03 17:36:37 +0900: : Started PATCH "/users/43" for ::1 at 2019-04-03 17:36:37 +0900
[INFO]2019-04-03 17:36:37 +0900: : Processing by UsersController#update as HTML
[INFO]2019-04-03 17:36:37 +0900: : Parameters: {"utf8"=>"✓", "authenticity_token"=>"5cFNucU6SLuSUeiSvu4QCRy7MvQ8BycoFF8wvfnbQ4tebelTt6U22hEFKiSAe7poNtdpBOY3k8SmtyUXez4lGA==", "user"=>{"user_image_attributes"=>{"id"=>"57"}, "name"=>"test", "user_info_attributes"=>{"sex"=>"", "birth_day(2i)"=>"1", "birth_day(3i)"=>"11", "birth_day(1i)"=>"0", "id"=>"3", "introduction"=>""}}, "commit"=>"Update", "id"=>"43"}
[DEBUG]2019-04-03 17:36:37 +0900: : User Load (1.1ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 43 ORDER BY `users`.`id` ASC LIMIT 1
[DEBUG]2019-04-03 17:36:37 +0900: : ↳ /Users/hasegawawataru/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.2.2.1/lib/active_record/log_subscriber.rb:98
[DEBUG]2019-04-03 17:36:37 +0900: : User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 43 LIMIT 1
[DEBUG]2019-04-03 17:36:37 +0900: : ↳ app/controllers/users_controller.rb:40
[DEBUG]2019-04-03 17:36:37 +0900: : (0.2ms) BEGIN
[DEBUG]2019-04-03 17:36:37 +0900: : ↳ app/controllers/users_controller.rb:41
[DEBUG]2019-04-03 17:36:37 +0900: : UserImage Load (0.5ms) SELECT `user_images`.* FROM `user_images` WHERE `user_images`.`user_id` = 43 LIMIT 1
[DEBUG]2019-04-03 17:36:37 +0900: : ↳ app/controllers/users_controller.rb:41
[DEBUG]2019-04-03 17:36:37 +0900: : UserInfo Load (0.4ms) SELECT `user_infos`.* FROM `user_infos` WHERE `user_infos`.`user_id` = 43 LIMIT 1
[DEBUG]2019-04-03 17:36:37 +0900: : ↳ app/controllers/users_controller.rb:41
[DEBUG]2019-04-03 17:36:37 +0900: : User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 43 LIMIT 1
[DEBUG]2019-04-03 17:36:37 +0900: : ↳ app/models/application_record.rb:56
[DEBUG]2019-04-03 17:36:37 +0900: : CACHE User Load (0.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 43 LIMIT 1 [["id", 43], ["LIMIT", 1]]
[DEBUG]2019-04-03 17:36:37 +0900: : ↳ app/models/application_record.rb:56
[DEBUG]2019-04-03 17:36:37 +0900: : UserInfo Update (0.3ms) UPDATE `user_infos` SET `sex` = '', `birth_day` = '0000-01-13', `updated_at` = '2019-04-03 08:36:37' WHERE `user_infos`.`id` = 3
[DEBUG]2019-04-03 17:36:37 +0900: : ↳ app/controllers/users_controller.rb:41
Line 3<br>
"user_info_attributes"=>{"sex"=>"", "birth_day(2i)"=>"1", "birth_day(3i)"=>"11", "birth_day(1i)"=>"0", "id"=>"3", "introduction"=>""}
1i =年
2i =月
3i =天
该日志表示birth_day参数为0000-01-11(年-月-日)。
Line 18<br>
[DEBUG]2019-04-03 17:36:37 +0900: : UserInfo Update (0.3ms) UPDATE `user_infos` SET `sex` = '', `birth_day` = '0000-01-13', `updated_at` = '2019-04-03 08:36:37' WHERE `user_infos`.`id` = 3
但是,“天”加2被注册到数据库中。
如果1i(年)不为0,而是1990,等等,则将成功注册而不加2。
我从Rails 5.2.2更新到5.2.2.1时在测试中发现,但是我不知道这是不是原因。
但是,当引入date_select函数时,它可以正常工作。
对这个错误有任何想法吗?
答案 0 :(得分:0)
由于更新查询的格式正确,看来数据库问题比Rails问题更多。也许您的数据库无法正确处理0年。
在数据库客户端中测试UPDATE user_infos SET sex = '', birth_day = '0000-01-13', updated_at = '2019-04-03 08:36:37' WHERE user_infos.id = 3
。