README.md in phony_rails-0.9.0 vs README.md in phony_rails-0.11.0
- old
+ new
@@ -49,22 +49,22 @@
#### General info
The `:default_country_code` options is used to specify a country_code when normalizing.
-PhonyRails will also check your model for a country_code method to use when normalizing the number. So `'070-12341234'` with `country_code` 'NL' will get normalized to `'317012341234'`.
+PhonyRails will also check your model for a country_code method to use when normalizing the number. So `'070-12341234'` with `country_code` 'NL' will get normalized to `'+317012341234'`.
You can also do-it-yourself and call:
# Options:
# :country_code => The country code we should use (forced).
# :default_country_code => Some fallback code (eg. 'NL') that can be used as default (comes from phony_normalize_numbers method).
PhonyRails.normalize_number('some number', :country_code => 'NL')
- PhonyRails.normalize_number('+4790909090', :country_code => 'SE') # => '464790909090' (forced to +46)
- PhonyRails.normalize_number('+4790909090', :default_country_code => 'SE') # => '4790909090' (still +47 so not changed)
+ PhonyRails.normalize_number('+4790909090', :country_code => 'SE') # => '+464790909090' (forced to +46)
+ PhonyRails.normalize_number('+4790909090', :default_country_code => 'SE') # => '+4790909090' (still +47 so not changed)
The country_code should always be a ISO 3166-1 alpha-2 (http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).
### Validation
@@ -100,10 +100,20 @@
You can validate against the normalized input as opposed to the raw input:
phony_normalize :phone_number, as: :phone_number_normalized, :default_country_code => 'US'
validates_plausible_phone :phone_number, :normalized_country_code => 'US'
+#### Allowing records country codes to not match phone number country codes
+
+You may have a record specifying one country (via a `country_code` attribute) but using a phone number from another country. For example, your record may be from Japan but have a phone number from the Philippines. By default, `phony_rails` will consider your record's `country_code` as part of the validation. If that country doesn't match the country code in the phone number, validation will fail.
+
+If you want to allow records from one country to have phone numbers from a different one, there are a couple of options you can use: `ignore_record_country_number` and `ignore_record_country_code`. Use them like so:
+
+ validates :phone_number, :phony_plausible => { :ignore_record_country_code => true, :ignore_record_country_number => true }
+
+Obviously, you don't have to use both, and you may not need or want to set either.
+
### Display / Views
In your views use:
<%= "311012341234".phony_formatted(:format => :international, :spaces => '-') %>
@@ -133,20 +143,9 @@
### Find by normalized number
Say you want to find a record by a phone number. Best is to normalize user input and compare to an attribute stored in the db.
Home.find_by_normalized_phone_number(PhonyRails.normalize_number(params[:phone_number]))
-
-## Changelog
-
-0.8.2
-* Added String#phony_normalized method
-
-## TODO
-
-* Make this work: Home.find_by_normalized_phone_number(Home.normalize_number(params[:phone_number]))
- So we use Home.normalize_number instead of PhonyRails.normalize_number. This way we can use the same default_country_code.
-* Make country_code method configurable.
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)