From 1d99a815630c34ca6d7c189b1d59396809f93467 Mon Sep 17 00:00:00 2001 From: Ryan Grimard Date: Fri, 27 Apr 2012 11:48:28 -0400 Subject: [PATCH 1/2] read_enumerated_attribute wasn't handling integer-based activerecord fields --- lib/enumerated_attribute/integrations/active_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/enumerated_attribute/integrations/active_record.rb b/lib/enumerated_attribute/integrations/active_record.rb index f4daa6d..e5423a0 100644 --- a/lib/enumerated_attribute/integrations/active_record.rb +++ b/lib/enumerated_attribute/integrations/active_record.rb @@ -39,7 +39,7 @@ def read_enumerated_attribute(name) return instance_variable_get('@'+name) unless self.has_attribute?(name) #this is an enumerated active record attribute val = read_attribute(name) - val = val.to_sym if !!val + val = val.to_s.to_sym if !!val val end From dd0484bef1968015f9ffcc8e1ae7f649d8262dc6 Mon Sep 17 00:00:00 2001 From: Ryan Grimard Date: Fri, 27 Apr 2012 13:58:56 -0400 Subject: [PATCH 2/2] few more calls to to_sym needed val.to_s.to_sym --- lib/enumerated_attribute/integrations/active_record.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/enumerated_attribute/integrations/active_record.rb b/lib/enumerated_attribute/integrations/active_record.rb index e5423a0..599854c 100644 --- a/lib/enumerated_attribute/integrations/active_record.rb +++ b/lib/enumerated_attribute/integrations/active_record.rb @@ -24,7 +24,7 @@ def write_enumerated_attribute(name, val) return write_attribute(name, val) unless self.class.has_enumerated_attribute?(name) val = nil if val == '' val_str = val.to_s if val - val_sym = val.to_sym if val + val_sym = val.to_s.to_sym if val return instance_variable_set('@'+name, val_sym) unless self.has_attribute?(name) write_attribute(name, val_str) val_sym @@ -57,7 +57,7 @@ def attributes atts = super atts.each do |k,v| if self.class.has_enumerated_attribute?(k) - atts[k] = v.to_sym if v + atts[k] = v.to_s.to_sym if v end end atts