Comments (8)
Hi Brian,
Thanks, and thanks for the issue. I am not sure what you exactly need. Is it the names of the countries, mapped to country codes, or "Switzerland (+41)", or just the country code itself in the select ("41")?
Cheers,
Florian
from phony.
Yep best would be country names mapped to codes like {"Switzerland" => 41, "United States" => 1}
etc. But anything close to that I could probably make it work.
from phony.
At the moment, Phony does not save any country names, since the focus is only on the numbers themselves. I did consider it, but including the names would bring with it a whole host of issues (multi-language names etc.).
Are there any country gems that have this mapping ready? (Maybe the "countries" gem?) If not, maybe we can work something out, perhaps a 3166 to country code mapping, to be required separately in Phony.
from phony.
The countries gem has a country_select
. It looks like you can get the country names mapped to country code with ISO3166::Country::Names
. Their yaml file has the country_codes also, I'll see if I can find a way to pull the hash I need out of it tomorrow. Thanks @floere !
from phony.
Hi Brian,
Glad to hear it! I'll think about doing a built-in solution.
Cheers,
Florian
from phony.
Hey, I figured it out with the countries
gem. You can do:
ISO3166::Country::Data.collect{|k,v| [v['name'], v['country_code']]}.sort
Since it's semi-expensive I cached it in a helper:
def cached_country_codes
Rails.cache.fetch('cached_country_codes', expires_in: 1.hour) do
ISO3166::Country::Data.collect{|k,v| [v['name'], v['country_code']]}.sort
end
end
Then you can call:
<%= f.select :country_code, options_for_select(cached_country_codes) %>
from phony.
Great! I wonder about the expires_in
– do countries change every hour? ;) But seriously: Good stuff! Cheers
from phony.
Thanks! You're right, prob a bit overkill :)
from phony.
Related Issues (20)
- Phony.plausible? returns false for a valid Belgian mobile phone number HOT 4
- warning: Capturing the given block using Proc.new is deprecated; use `&block` instead HOT 2
- Phony.normalize('6502001382') returns '652001382' -- '0' was lost HOT 1
- Phony.plausible? returns false for a valid Belgian phone number HOT 2
- Numbering plan of Cote d'Ivoire/Ivory Coast has changed HOT 1
- Handle country codes for countries related to the united states with area code part of the country calling code +1-xxx HOT 3
- Globaltel Serbia phone numbers are not plausible
- Phony plausible? returns false for 3 digit locals with 3 digit NDC (German Numbers) HOT 5
- `false` is being inserted into formatted phone number, when no NDC is being used HOT 3
- Mauritan number definition does split but normalize HOT 3
- Samoa valid number that starts with "71" was not validated HOT 3
- Phony.plausible? returns false for valid Columbian numbers HOT 2
- Valid Italian phone number fails plausibility check HOT 2
- Proposal for "no RAM" mode HOT 4
- Nine digits Brazilian cellphone numbers HOT 2
- Dial code not added when the phone number has just the leading 00 but no actual dial code. HOT 2
- Valid Italian Landline numbers fails plausibility check HOT 1
- Validations failing for Vietnamese number HOT 2
- Valid phone numbers of Luxembourg don't pass the plausibility check HOT 2
- Number is normalized incorrectly in some cases
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phony.