aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-07-17 17:38:59 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-07-17 17:38:59 -0300
commit8e3d9438390c6277ee14f00f773d2c440e7cf4d5 (patch)
tree7aa38b33433539ec491e55b02e55783900161986 /activerecord/lib/active_record
parentc64bff2c87ebf363703c63ecd4a96d56a1a78364 (diff)
parentdd02463a26f3d9cd20bb6fb5ef84e0df7477c75d (diff)
downloadrails-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.rb7
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