{"id":19856945,"url":"https://github.com/johnvuko/jt-rails-address","last_synced_at":"2025-10-07T12:58:26.707Z","repository":{"id":35467101,"uuid":"39735268","full_name":"johnvuko/jt-rails-address","owner":"johnvuko","description":"Postal addresses management in Ruby On Rails and Javascript","archived":false,"fork":false,"pushed_at":"2016-09-20T09:17:49.000Z","size":11,"stargazers_count":42,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-22T12:59:23.999Z","etag":null,"topics":["address","rails","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johnvuko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-26T17:47:56.000Z","updated_at":"2024-09-16T13:27:14.000Z","dependencies_parsed_at":"2022-09-07T18:01:57.652Z","dependency_job_id":null,"html_url":"https://github.com/johnvuko/jt-rails-address","commit_stats":null,"previous_names":["johnvuko/jt-rails-address"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnvuko%2Fjt-rails-address","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnvuko%2Fjt-rails-address/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnvuko%2Fjt-rails-address/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnvuko%2Fjt-rails-address/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnvuko","download_url":"https://codeload.github.com/johnvuko/jt-rails-address/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251972403,"owners_count":21673599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["address","rails","ruby"],"created_at":"2024-11-12T14:17:02.753Z","updated_at":"2025-10-07T12:58:21.675Z","avatar_url":"https://github.com/johnvuko.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JTRailsAddress\n\n[![Gem Version](https://badge.fury.io/rb/jt-rails-address.svg)](http://badge.fury.io/rb/jt-rails-address)\n\nJTRailsAddress simplify postal addresses management and geocoding with Google Maps API in Ruby On Rails and Javascript.\n\n## Installation\n\nJTRailsAddress is distributed as a gem, which is how it should be used in your app.\n\nInclude the gem in your Gemfile:\n\n    gem 'jt-rails-address', '~\u003e 1.0'\n\n## Usage\n\n### Basic usage\n\nIn your migration file:\n\n```ruby\nclass CreateUsers \u003c ActiveRecord::Migration\n\tdef change\n\t\tcreate_table :users do |t|\n\n\t\t\tt.string :username, null: false\n\t\t\tt.string :email, null: false\n\t\t\tt.string :password_digest\n\n\t\t\t# Each field will be prefixed by 'address_'\n\t\t\tt.address :address\n\n\t\t\tt.timestamps null: false\n\t\tend\n\tend\nend\n```\n\nIt will create all the fields you need for address management:\n\n- `formatted_address`, \"Empire State Building, 350 5th Ave, New York, NY 10118\"\n- `street_number`, \"350\"\n- `street_name`, \"5th Ave\"\n- `street`, \"350 5th Ave\", it's the concatenation of `street_number` and `street_name`\n- `city`\n- `zip_code`\n- `department`\n- `department_code`\n- `state`\n- `state_code`\n- `country`\n- `country_code`\n- `lat`, GPS latitude\n- `lng`, GPS longitude\n\nThere are also `add_address` and `remove_address` methods for migrations.\n\nIn your model:\n```ruby\nclass User \u003c ActiveRecord::Base\n\n    # Add a virtual field named `address` and a class method `address_fields` returning `JT::Rails::Address.fields` prefixed by `address_` in this case\n    has_address :address\n\nend\n```\n\n### Javascript usage with Google Maps API\n\nYou probably want to use an autocompletion service like Google Maps API.\n\nIn your HTML:\n```html\n\u003c!-- Basic form, address is just a virtual field used for searching the address on Google Maps API --\u003e\n\u003c%= form_for @user do |f| %\u003e\n\n\t\u003cdiv class=\"jt-address-autocomplete\"\u003e\n\t\t\u003c!-- This field is used to search the address on Google Maps --\u003e\n\t\t\u003c%= f.text_field :address, class: 'jt-address-search' %\u003e\n\n\t\t\u003c!-- All fields are hidden because the javascript will set their value automatically --\u003e\n\t\t\u003c% for attr in JT::Rails::Address.fields %\u003e\n\t\t\t\u003c%= f.hidden_field \"address_#{attr}\", class: \"jt-address-field-#{attr}\" %\u003e\n\t\t\u003c% end %\u003e\n\t\u003c/div\u003e\n\n\t\u003c!-- Optional, if this field is true, the address will be remove --\u003e\n\t\u003c%= f.check_box :address_destroy %\u003e\n\n\t\u003c%= f.submit %\u003e\n\n\u003c% end %\u003e\n\n\u003c!-- Load Google Maps and call googleMapInitialize when it's done --\u003e\n\u003cscript async type=\"text/javascript\" src=\"//maps.googleapis.com/maps/api/js?libraries=places\u0026callback=googleMapInitialize\u0026key=YOUR_GOOGLE_API_KEY\"\u003e\u003c/script\u003e\n```\n\nIn your `applicaton.js` you have to add:\n```javascript\n//= require jt_address\n\n// This function is call when Google Maps is loaded\nwindow.googleMapInitialize = function(){\n\n    // Simple usage\n    $('.jt-address-autocomplete').jt_address();\n    \n    // Advanced usage with google options\n    $('.jt-address-autocomplete').jt_address({\n        type: ['restaurant'],\n        componentRestrictions: { country: 'fr' }\n    });\n\n};\n```\n\nEach time the data for the address change, an event `jt:address:data_changed` is triggered.\nYou can catch it with:\n\n```javascript\n$('.jt-address-autocomplete').on('jt:address:data_changed', function(event, data){\n\tconsole.log(data);\n});\n\n```\n\n### Google Maps API in Ruby\n\nThanks to [graticule](https://github.com/collectiveidea/graticule), there is a simple way to use autocomplete in Ruby.\n\n```ruby\n# Simple usage\ndata = JT::Rails::Address.search(\"Eiffel Tower\", \"YOUR GOOGLE API KEY\")\n\n# Advanced usage\ndata = JT::Rails::Address.search(\"Eiffel Tower\", \"YOUR GOOGLE API KEY\", {components: 'country:fr'})\n\n# Use the data retrieve from Google Maps API\nmy_instance.load_address(:address, data)\n\n# Use the set a nil all address fields\nmy_instance.reset_address(:address)\n\n# Use the set a nil all address fields with HTML forms\nmy_instance.update({address_destroy: true})\n```\n\n## Author\n\n- [Jonathan Tribouharet](https://github.com/jonathantribouharet) ([@johntribouharet](https://twitter.com/johntribouharet))\n\n## License\n\nJTRailsAddress is released under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnvuko%2Fjt-rails-address","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnvuko%2Fjt-rails-address","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnvuko%2Fjt-rails-address/lists"}