{"id":19337494,"url":"https://github.com/berlinmagic/magic_addresses","last_synced_at":"2025-02-24T08:15:10.531Z","repository":{"id":27198148,"uuid":"30668550","full_name":"berlinmagic/magic_addresses","owner":"berlinmagic","description":"adds translated addresses to any rails app.","archived":false,"fork":false,"pushed_at":"2016-11-29T16:42:51.000Z","size":628,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-06T10:22:14.418Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/berlinmagic/magic_addresses","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/berlinmagic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-11T20:37:50.000Z","updated_at":"2016-11-29T16:42:53.000Z","dependencies_parsed_at":"2022-08-17T17:15:13.213Z","dependency_job_id":null,"html_url":"https://github.com/berlinmagic/magic_addresses","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berlinmagic%2Fmagic_addresses","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berlinmagic%2Fmagic_addresses/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berlinmagic%2Fmagic_addresses/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berlinmagic%2Fmagic_addresses/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/berlinmagic","download_url":"https://codeload.github.com/berlinmagic/magic_addresses/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240441950,"owners_count":19801793,"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":[],"created_at":"2024-11-10T03:14:29.683Z","updated_at":"2025-02-24T08:15:10.493Z","avatar_url":"https://github.com/berlinmagic.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MagicAddresses\n\nAn address gem for rails .. fetches *country*, *state*, *city*, *district* and *subdistrict* in seperated and translated models.\n\nThis gives the great advantage, that each address can be displayed in each language. And not matter how you write an address it fetches the right one.\nFor example the german city *munich* in german *München* .. both save a city-model with a name translated all app-locales. \n\n```ruby\nrails g magic_addresses:install\n```\n\n- 1. **check the initialers** (*its important to first check the settings of the gem*)\n- 2. **check the migration file**\n- 3. **run `rake db:migrate`**\n- 4. **add to your models**\n\n\n## Features\n\n- full tranlated addresses\n- allways correct addresses (query to google/verbatim service)\n- addresses, cities, countries, and so one, are uniq (i.e. only one \"New-York\" with lots of addresses, districts, ..)\n- perfect order ( city has X addresses )\n- postgresql earthdistance included (for distance checks)\n- tested\n\n\n\n\n## News\n##### since version `0.0.44` there are named addresses, so one model can have multiple-times one-address\n\nrun:\n```ruby\nrails g magic_addresses:add_named_addresses\n.. or ..\nrails g magic_addresses:update\n```\nand migrate your Database\n \n\nModel-Example\n```ruby\nclass Customer \u003c ActiveRecord::Base\n  \n  has_one_address()\n  has_one_named_address( \"invoice_address\" )\n  has_one_named_address( \"delivery_address\" )\n  \nend\n```\n\n\n \n\n\n##### since version `0.0.13` addresses are uniq, so the same address never will be saved twice, instead owners share one address\n\nrun:\n```ruby\nrails g magic_addresses:update\n```\nto update old addresses and add the new structure\n\n\n##### You can add Earthdistance plugin later!\nrun:\n```ruby\nrails g magic_addresses:add_earthdistance\n```\nbe sure to activate it in initializer before migrate!\n\n\n\n### Model methods\n\n```ruby\n  has_one_address     # =\u003e This model has one address associated with it. (ie: User)\n\n  has_addresses       # =\u003e This model has many addresses. (ie: Company)\n\n  # You can use `has_one_address` and `has_addresses` on the same model \n  # `has_one_address` sets the default flag so could be major address.\n\n  ## NEW:\n  \n  has_one_named_address( \"name_me\" )\n  \n  # works together with the other both .. so models can have multiple single addresses\n  # ie:\n  has_one_address()\n  has_one_named_address( \"invoice_address\" )\n  has_one_named_address( \"delivery_address\" )\n  \n  \n  ## UNSTABLE: \n  has_nested_address  # =\u003e Has one directly nested addresses. (ie: User.street, User.city)\n\n```\n\n### View Mehtods\n\n```ruby\n  \n  \u003c%= country_flag( :de, \"small\" ) %\u003e\n  # flag helper for all default countries ( \"small\" | \"medium\" | \"large\")\n  \n  \u003c%= render \"magic_addresses/addresses/fields/address\", f: f %\u003e\n  # form helper for 'has_one_address'\n  \n```\n\n\n**NEW** since *v. 0.0.25*:\nrewrite the template of admin views, just place [admin_template](https://github.com/berlinmagic/magic_addresses/tree/master/app/views/magic_addresses/_admin_template.html.erb) in *YOUR_PROJECT/app/views/magic_addresses/_admin_template.html.erb* and rewrite it for your needs ...\n\n\n### in your Controllers:\n\n```ruby\n  \n  private\n  \n    # Never trust parameters from the scary internet! ... has_one_address\n    def instance_params\n      params.require(:instance).permit( .. :address_attributes =\u003e [:id, :street, :number, :postalcode, :city, :country, :_destroy] .. )\n    end\n    \n    \n    # Never trust parameters from the scary internet! ... has_addresses\n    def instance_params\n      params.require(:instance).permit( .. :addresses_attributes =\u003e [:id, :street, :number, :postalcode, :city, :country, :_destroy] .. )\n    end\n  \n  - or -\n  \n  :address_attributes =\u003e MagicAddresses::Address::PARAMS      # has_one_address\n  :addresses_attributes =\u003e MagicAddresses::Address::PARAMS    # has_addresses\n  \n```\n\n\n## Configuration\n```ruby\n  \n  MagicAddresses.configure do |config|\n    # in which locales addresses should be saved\n    config.active_locales = [:en, :de]\n    # what is the default language (should be :en, except you don't need english at all)\n    config.default_locale = :en\n    # what is the default country for query\n    config.default_country = \"Germany\"\n    # add default country in each query ?\n    config.query_defaults = true\n    # only save tranlations when differs from default-locale?\n    config.uniq_translations = true\n    # use a background-process for the lookups ( :none | :sidekiq )\n    config.job_backend = :none\n    # use a postgres earthdistance for distance calculation\n    config.earthdistance = false\n  end\n  \n```\n\n\n\n#### Structure\n\nAddress:\n- street *(globalized)*\n- street_additional\n- number\n- postalcode\n- **country**\n- - name *(globalized)*\n- - iso_code\n- - dial_code *(phone)*\n- **state**\n- - name *(globalized)*\n- - short_name\n- **city**\n- - name *(globalized)*\n- - short_name\n- **district**\n- - name *(globalized)*\n- - short_name\n- **subdistrict**\n- - name *(globalized)*\n- - short_name\n\n\n#### Getter \u0026 Setter\n```ruby\n  :street\n  :number\n  :postalcode\n  :city\n  :district\n  :subdistrict\n  :state\n  :country\n```\n\n\n#### TESTs\nsince version 0.0.24 you can only run rspec from the project folder:\n```ruby\n~/Sites/magic_addresses:$ rspec spec\n```\nthe symlink in the dummy folder is removed for compatibility with ruby 2.2\n\n\n\n\n\n.. will add more info, sometimes ...\n\n\nThis project rocks and uses MIT-LICENSE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fberlinmagic%2Fmagic_addresses","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fberlinmagic%2Fmagic_addresses","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fberlinmagic%2Fmagic_addresses/lists"}