diff --git a/.gitignore b/.gitignore index 5e4a47c..4eb7cd9 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ vendor lib/tasks/* TODO.rdoc webrat-*.html +/.project diff --git a/lib/enumerated_attribute/integrations/active_record.rb b/lib/enumerated_attribute/integrations/active_record.rb index f4daa6d..0f109c2 100644 --- a/lib/enumerated_attribute/integrations/active_record.rb +++ b/lib/enumerated_attribute/integrations/active_record.rb @@ -21,7 +21,15 @@ def validate_enumerated_attribute def write_enumerated_attribute(name, val) name = name.to_s - return write_attribute(name, val) unless self.class.has_enumerated_attribute?(name) + unless self.class.has_enumerated_attribute?(name) + # allow for 'virtual' attributes such as when using Devise (:password, :confirm_password) + setter = "#{name}=".to_sym + if !self.attribute_names.include?(name) && self.methods.include?(setter) + return self.send(setter, val) + else + return write_attribute(name, val) + end + end val = nil if val == '' val_str = val.to_s if val val_sym = val.to_sym if val @@ -103,7 +111,7 @@ def new(*args, &block) result end end - unless private_method_defined?(:method_missing_without_enumerated_attribute) + unless method_defined?(:method_missing_without_enumerated_attribute) || private_method_defined?(:method_missing_without_enumerated_attribute) define_chained_method(:method_missing, :enumerated_attribute) do |method_id, *arguments| arguments = arguments.map{|arg| arg.is_a?(Symbol) ? arg.to_s : arg } method_missing_without_enumerated_attribute(method_id, *arguments)