Permalink
Browse files

Fix multiple phone attributes rendering error.

  • Loading branch information...
1 parent 053f6ba commit 604628d9bae4edcff2d0dc4f64aee05a7c5a6b8d @btelles committed Feb 2, 2010
View
@@ -23,7 +23,7 @@ PKG_FILES = FileList[
spec = Gem::Specification.new do |s|
s.name = "validates_and_formats_phones"
- s.version = "0.0.2"
+ s.version = "0.0.3"
s.author = "Bernie Telles"
s.email = "btelles@gmail.com"
@@ -30,23 +30,17 @@ def validates_and_formats_phones(*args)
record.errors.add attr, "must have #{size_options[0]} digits."
end
else
- record.format_phone_fields(fields, formats)
+ record.format_phone_field(attr, formats)
end
end
end
end
module InstanceMethods
- def format_phone_fields(fields = [:phone], formats = [])
- formats << DEFAULT_FORMAT if formats.empty?
- fields.each do |field_name|
- format_phone_field(field_name, formats) unless send(field_name).blank?
- end
- end
def format_phone_field(field_name, formats = [])
formats << DEFAULT_FORMAT if formats.empty?
- self.send("#{field_name}=", self.send(field_name).to_s.to_phone(formats))
+ self.send("#{field_name}=", self.send(field_name).to_s.to_phone(formats)) unless send(field_name).blank?
end
end
end
View
@@ -4,6 +4,7 @@
end
create_table :options_phones, :force => true do |t|
t.string :other_phone
+ t.string :fax
end
end
@@ -4,7 +4,7 @@ class Phone < ActiveRecord::Base
validates_and_formats_phones
end
class OptionsPhone < ActiveRecord::Base
- validates_and_formats_phones :other_phone,
+ validates_and_formats_phones :other_phone, :fax,
'####-####',
'(###) ###-####'
end

0 comments on commit 604628d

Please sign in to comment.