aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib')
-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