I need a select statement where the user selects a country. I'm going to store the corresponding country code. The will be in a view _form, so it must work for both add and update.
For update, I must have a selected option for the current country, but country_select doesn't allow that. I'm also trying to use country_options_for_select, which does give me the ability to pre-select a country, but I can't tell how to get the country that the user selects.
Do you need to include 'all' the countries, like on an order form?
If you only need a limited set: put them in a table.
.. that's what I did, but I only needed 9 countries..
BTW, if you're interested: I'm gonna implement geoIP using this database in MySQL (there seems to be a PEAR class for lookups) to have an automatic default country selection.
geoIP looks interesting, Thijs. I have a table with 274 countries in it that I was going to use, but Bermi has a country/abbreviation lookup table in AK_COUNTRIES that I was decided to use instead, mainly because I'm trying to document the API.
Perhaps we can also write and document a select statement for geoIP. If you do, please write an installer to create and populate the table. Also, please document what you do in the Documentation Forum until the core team decides whether or not it should be put in the Wiki.
I'm going to try to add a selected option for country_select as it seems to be the only way to accomplish what I need to do unless I find a better solution first.
Core team members, how do you feel about having different means of accomplishing the same task documented in the Wiki?
Alake, the core team does not have control over what is published on the wiki. A future manual might come from the wiki and if we have 2 choices, we will go with the simplest one.
Regarding the wiki, you're the one who has invested more time on it, doing a great job, so you are better suited to model it as you think is better for the Akelos community. Especially for first comers who don't feel comfortable with learning Akelos by reading inline docs, reading unit tests and digging into the code.
By the way, have a look at what I coded for geolocating visitors. As I don't like move and update the large DB across applications, I this very simple REST services for my projects. On the page you have the details of the database I'm using. Please drop me a line if you want the source (old and smelly, but working code).
Yes, Bermi, I would like the source. Because I'm new to REST, I'd also like to know what is "old and smelly" about it, that is, what needs to be fixed. Can you send me to a place where I can learn how to create a REST service and how reference to it can be best integrated into an Akelos project? Is Thijs' geoIP better than what you have now, Bermi? Can it be integrated into a REST interface?
The sub-project that I want this country information in is a user profile and log in project that I want to release to the Akelos community, for I can see that many projects need something like this. What is the best way to upload pieces of code for sharing?
Alan, the REST on this geoip webservice is pretty simple and can be integrated into Akelos like
$country = Ak::url_get_contents('http://webservices.akelos.com/ip2country/'.AK_REMOTE_IP);
I attached to this comment my geoIp solution. I'm not sure about the differences between Thijs proposal and mine. They seem quite similar.
Right now a good place for code pastes is http://paste.lisp.org/new/akelos, although it would be nice to have a tagged/ranked repository-site of snippets for the community.
I'm going to use Bermi's geoIp solution, but with modifications. I'd like this web service to be able to work with more geographic information in the future, so I want to make this web service compatible with those requirements. The profile that I plan to release to the Akelos community needs to be able to convert country codes (2 and 3 character) to and from country names. This is my first foray into REST, so wish me well.
I'm not sure about the differences between Thijs proposal and mine. They seem quite similar.
I guess they are. There might be some minor differences in the used databases (CSV files), but who cares.
Bermi, it's great to see you already coded up a solution. I would rather use your solution since it will save me the work of implementing the maxmind CSV. And it returns ISO 3166-3 (the two-letter code), just what I needed.
Can I make REST calls to your 'webservices' URL for the Energy Neighbourhood website?
I guess it will be around 5000 users, each making their first arrival on the website (resulting in an IP lookup, result saved in a cookie) in October and November.
Forget what I asked above.
I just saw the notice on the webservice page:
This Webservice should not be used in production sites as whenever this site goes down your application will break. Please contact us to get the source we are using here and remember to cache your visitors results so you don't hit this service twice for the same IP.
And the source code is easy enough to implement. I'll use that.
Thanks anyway, it'll save me loads of time in an already tight schedule.
My webservices solution will enable you to have the services on your server. I'm testing it now.
Can you send me to a place where I can learn how to create a REST service and how reference to it can be best integrated into an Akelos project?
Alake, you've got the rails book, haven't you? (Agile Web Development with Rails) There a good explanation of the REST concept in it. See 'Resource-Based Routing' in the chapter on Action Controller (chapter 20)
Yes, I do have it. Thanks for the reminder. I haven't looked in it for a while.
For your coding pleasure, the Howto section of the Wiki now tells you how to create a country webservice on your server. I have it installed on my server, which you may use for demos.
My next project will be to add to this webservice the ability to create a select statement compatible with country_select.
I created the installation instructions from my installation. When someone installs this webservice from the instructions, I'd like a comment on how your installation goes and what modifications you had to make.
Hats off to Alan!
I'll have to update my web service with your improvements :)
BTW, here is the link to the how-to wiki page
Thanks, Bermi. When I look into the code of Akelos, I have to put Bermi in the category of programmers I hold in awe.
I'm rethinking my idea of making a country select from a web service, because this would mean that anyone using it would have to have the web service installed. Instead, we might use the web service to generate AkCountries and modify it to return either a 2 character code or a 3 character code, then modify country_select to add the options to
Comments, anyone?
Alan thanks for those nice words. I feel the same when I look at Kaste contributions, or some Rails core developers.
I'll start coding a USA Real Estate portal on May that requires GeoLocation and I thought that porting a plugin like GeoKit for Akelos would be great.
This could be the start of such a plugin. It could override default country_select helper methods with more intelligent ones using the ip2location database.
The plugin could download the CSV and populate the database when installed. After that it could have an utility script like app/vendor/plugins/geokit/scripts/update_database which could run in a cron job.
The GeoKit plugin provides some other great features like acts_as_mapeable which allows to perform distance searches on Active Records. It uses Google and Yahoo geocoding API's for locating physical addresses.
Let me know if you're interested in maintaining such a plugin so I can create http://svn.akelos.org/plugins/geokit/ and give you access.
Great stuff Alan!
I've installed your country webservice on my webserver, and I'm making queries from within Akelos to get a countries ISO code.
I did come across one problem though: the AK_REMOTE_IP constant seems to contain the 'IP address' (example 62.88.39.67) and your webservice takes the 'IP number' (which would be 1045964611). Bermi's ip2country takes the IP address, so I could find in his code what I needed to change. In country.php I changed line 23:
$sql = "SELECT abbr_3 FROM ip_countries
WHERE fromIp <= '$data' AND toIp >= '$data'";
to:
$sql = "SELECT abbr_3 FROM ip_countries
WHERE fromIp <= inet_aton('$data') AND toIp >= inet_aton('$data')";
and now it gives a result for the AK_REMOTE_IP constant.
1 to 17 of 17