在date_select中,当“0”放入“年”时,将2添加到“日”

问题描述 投票:0回答:1

Rails 5.2.2.1 我觉得你不明白我说的是什么,我把日志解释一下。

Log

[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

Detail

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

但是,“day”加2在数据库中注册。 如果1i(年)不是0但是1990年等,它将成功注册而不是加号2。

Discovery history

我在测试中发现我从Rails 5.2.2更新到5.2.2.1,但我不知道这是否是原因。 但是,当引入date_select函数时,它没有任何问题。

对这个bug的任何想法?

ruby-on-rails ruby-on-rails-5
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.