diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-07-17 17:38:59 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-07-17 17:38:59 -0300 |
commit | 8e3d9438390c6277ee14f00f773d2c440e7cf4d5 (patch) | |
tree | 7aa38b33433539ec491e55b02e55783900161986 /activerecord/lib/active_record | |
parent | c64bff2c87ebf363703c63ecd4a96d56a1a78364 (diff) | |
parent | dd02463a26f3d9cd20bb6fb5ef84e0df7477c75d (diff) | |
download | rails-8e3d9438390c6277ee14f00f773d2c440e7cf4d5.tar.gz rails-8e3d9438390c6277ee14f00f773d2c440e7cf4d5.tar.bz2 rails-8e3d9438390c6277ee14f00f773d2c440e7cf4d5.zip |
Merge pull request #16188 from marianovalles/fix_rational_to_decimal_type_cast
Fix rational to decimal on type_cast_from_user
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/type/decimal.rb | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/type/decimal.rb b/activerecord/lib/active_record/type/decimal.rb index a9db51c6ba..27566cf856 100644 --- a/activerecord/lib/active_record/type/decimal.rb +++ b/activerecord/lib/active_record/type/decimal.rb @@ -14,10 +14,13 @@ module ActiveRecord private def cast_value(value) - if value.respond_to?(:to_d) + case value + when ::Numeric, ::String + BigDecimal(value, precision.to_i) + when proc { value.respond_to?(:to_d) } value.to_d else - value.to_s.to_d + cast_value(value.to_s) end end end |