-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Country code is re-added if phone number is wrong length #180
Comments
Possible that |
Not sure why this happens. Please elaborate on your (model) setup. |
Our class User < ActiveRecord::Base
include CountryCode
phony_normalize :phone_number, default_country_code: 'US'
end The user model has an attribute called "country", which is either "AUS" or "US", so we use a little library to translate that into the proper country codes of "AU" or "US", in module CountryCode
# country code necessary for going_postal & phony_rails gems
def country_code
if country.present? && country == "AUS"
"AU"
else
"US"
end
end
end |
Thanks. If you could give an example (eg. an example like given in #187) it might help to find the problem. |
This could be solved by it #190. |
@milesmatthias is this still an issue? I added a test that shows it should not happen. |
@joost This is still an issue. Basically if you don't validate your phone number before normalizing, and the number is invalid it will append the country code to the number every time your model is updated. If you look at the
I don't understand why it's appending
This seems to solve the issue when I run it in the rails console, but I haven't run it against your test suite yet. Thoughts? P.S. #190 doesn't solve this issue because we aren't using validation here. |
Hey, just confirming that I am seeing the same |
A perfectly valid response to this is that it's the application's responsibility, but I think it could be a nice option here.
We have US & Australian users, and if an Australian user puts in a phone number that is longer than 9 digits (ie: an American doing Australian testing, so they put in their 10 digit US number), phony_rails re-adds the country code (+61 in the case of Australia) to the phone number every time the user record is saved.
So we ended up with a couple user records with super long phone numbers (
+61616161616161615555555555
).It'd be great if there was a config option for how to handle this situation that phony_rails just handled. Ex: truncate first 9 digits, truncate last 9 digits, etc. Or maybe there is, and I just missed it in the docs.
The text was updated successfully, but these errors were encountered: