aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorMariano Valles <mariano.valles@wooga.com>2014-07-16 13:20:53 +0200
committerMariano Valles <mariano.valles@wooga.com>2014-07-16 13:20:53 +0200
commita4802e217e95af14ca6ae13ab72ff3b44e2b4217 (patch)
tree1465ab68a1356a984bdd4133e10a9873c974396b /activerecord/lib
parentc3f4d6c8feafab9ded8b549d745c4731ee17b5c4 (diff)
downloadrails-a4802e217e95af14ca6ae13ab72ff3b44e2b4217.tar.gz
rails-a4802e217e95af14ca6ae13ab72ff3b44e2b4217.tar.bz2
rails-a4802e217e95af14ca6ae13ab72ff3b44e2b4217.zip
Fix rational to decimal on type_cast_from_user
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/type/decimal.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/type/decimal.rb b/activerecord/lib/active_record/type/decimal.rb
index a9db51c6ba..33d4e37ea3 100644
--- a/activerecord/lib/active_record/type/decimal.rb
+++ b/activerecord/lib/active_record/type/decimal.rb
@@ -14,7 +14,9 @@ module ActiveRecord
private
def cast_value(value)
- if value.respond_to?(:to_d)
+ if value.class == Rational
+ BigDecimal.new(value, precision.to_i)
+ elsif value.respond_to?(:to_d)
value.to_d
else
value.to_s.to_d