diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2016-10-04 17:37:04 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-04 17:37:04 -0400 |
commit | de9a56b66af928a09f85daf15ffb1c2023a7c1b8 (patch) | |
tree | f3ec18064c3b14d3b8448b3a35e0e69550bac67c /activemodel/lib/active_model | |
parent | 4d6feef79248a63c4cefde3f9ceb2242925e8d8d (diff) | |
parent | 26fe640c9ae644b280b1d01a0d162422995647d6 (diff) | |
download | rails-de9a56b66af928a09f85daf15ffb1c2023a7c1b8.tar.gz rails-de9a56b66af928a09f85daf15ffb1c2023a7c1b8.tar.bz2 rails-de9a56b66af928a09f85daf15ffb1c2023a7c1b8.zip |
Merge pull request #24571 from raimo/patch-1
Print the proper ::Float::INFINITY value when used as a default value
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/type/float.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/type/float.rb b/activemodel/lib/active_model/type/float.rb index 94bb7e700c..4d0d2771a0 100644 --- a/activemodel/lib/active_model/type/float.rb +++ b/activemodel/lib/active_model/type/float.rb @@ -7,6 +7,15 @@ module ActiveModel :float end + def type_cast_for_schema(value) + return "::Float::NAN" if value.try(:nan?) + case value + when ::Float::INFINITY then "::Float::INFINITY" + when -::Float::INFINITY then "-::Float::INFINITY" + else super + end + end + alias serialize cast private |