Peripatetic This gem adds location functionality to any app it create 3 tables in the database (locations, countries, and postal_codes) and populates countries and postal_codes from a compressed yaml file. One may specify wether it be has_one or has_many. The countries and postal_codes table are just look up tables. in the form partial the gem guesses the country and zip code from the ip and fills it in. If it takes too long or the data is not there it doesn't populate it. The country table has a position field which you can use to order the countries. If a user adds a street address then it geocodes it and adds the updated lat lng to the locations table.
the postal codes are from geonames and the f
countries db is from https://github.com/hexorx/countries the postal_codes db is from http://download.geonames.org/export/dump/ and http://federalgovernmentzipcodes.us/
The US postal_codes lat and lng columns have been recently updated.
Drop in Location for any model has_one or has_many, creates a nested association and allows you to drop into your form a partial
Installation:
Add this line to your application's Gemfile:
gem 'peripatetic'
And then execute:
$ bundle
Or install it yourself as:
$ gem install peripatetic
Usage:
Add include Peripatetic to the model you want locations then just drop in nested form into the form
<%= f.fields_for peripatetic_locations(model, number_of_times_to_build) do |builder| %>
<% if builder.object.new_record? %>
<%= builder.hidden_field :ip, :value => ip_address %>
<%= builder.text_field :street %>
<%= builder.text_field :accessor_postal_code, :value => get_accessor_postal_code(builder.object)[:postal_code] %>
<%= builder.country_select :accessor_country, get_accessor_postal_code(builder.object)[:country] %>
<% end %>
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request