{"id":22144979,"url":"https://github.com/jim/carmen-demo-app","last_synced_at":"2025-07-26T02:31:02.791Z","repository":{"id":2810985,"uuid":"3812241","full_name":"jim/carmen-demo-app","owner":"jim","description":"A sample application that illustrates how to use carmen-rails.","archived":false,"fork":false,"pushed_at":"2022-07-21T22:19:33.000Z","size":50,"stargazers_count":19,"open_issues_count":9,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-04-11T04:52:04.983Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"bookingbricks/file-upload-example","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-03-23T20:23:12.000Z","updated_at":"2021-03-11T20:15:21.000Z","dependencies_parsed_at":"2022-08-08T08:30:22.978Z","dependency_job_id":null,"html_url":"https://github.com/jim/carmen-demo-app","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jim%2Fcarmen-demo-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jim%2Fcarmen-demo-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jim%2Fcarmen-demo-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jim%2Fcarmen-demo-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jim","download_url":"https://codeload.github.com/jim/carmen-demo-app/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227641436,"owners_count":17797838,"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-12-01T22:36:53.777Z","updated_at":"2024-12-01T22:36:54.323Z","avatar_url":"https://github.com/jim.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# carmen-rails Demo App\n\nThis app is a proof of concept to illustrate how to use\n[carmen-rails](https://github.com/jim/carmen-rails) inside a simple form in a Rails\napp.\n\ncarmen-rails depends upon [carmen](https://github.com/jim/carmen) for its\ngeographic data. If you want to customize the data generated by these helpers,\nthe Carmen docs explain how.\n\nThroughout this example, it is assumed that the code is operating on an `Order`\nmodel. Be sure to change all references to `order` to whatever is appropriate\nfor your application.\n\n## Setup\n\nAdd `carmen-rails` to your Gemfile:\n\n```ruby\ngem 'carmen-rails'\n```\n\nUse the new form helpers provided by carmen-rails to add country or subregion\nselects to your form:\n\n```erb\n\u003cdiv class=\"field\"\u003e\n  \u003c%= f.label :country_code %\u003e\u003cbr /\u003e\n  \u003c%= f.country_select :country_code, priority: %w(US CA), prompt: 'Please select a country' %\u003e\n\u003c/div\u003e\n```\n That's all there is to it. If you want to support a subregion field and have\n the options inside it updated by value in the country select, place this input\n inside a partial:\n\n```erb\n\u003cdiv class=\"field\"\u003e\n  \u003c%= f.label :state_code %\u003e\u003cbr /\u003e\n  \u003c%= render partial: 'subregion_select', locals: {parent_region: f.object.country_code} %\u003e\n\u003c/div\u003e\n```\n\nHere is the content of the `subregion_select` partial:\n\n```erb\n\u003cdiv id=\"order_state_code_wrapper\"\u003e\n  \u003c% parent_region ||= params[:parent_region] %\u003e\n  \u003c% country = Carmen::Country.coded(parent_region) %\u003e\n\n  \u003c% if country.nil? %\u003e\n    \u003cem\u003ePlease select a country above\u003c/em\u003e\n  \u003c% elsif country.subregions? %\u003e\n    \u003c%= subregion_select(:order, :state_code, parent_region) %\u003e\n  \u003c% else %\u003e\n    \u003c%= text_field(:order, :state_code) %\u003e\n  \u003c% end %\u003e\n\u003c/div\u003e\n```\n\nNote that we're defaulting to a text field input when we don't have subregion\ninformation for a country, and that if we don't have a country at all, we show\na simple message.\n\nNow we will add a small script that replaces the subregion select when the country\nselect's value changes. A wrapper div has been added to make this simpler.\n\n```coffeescript\n$ -\u003e\n  $('select#order_country_code').change (event) -\u003e\n    select_wrapper = $('#order_state_code_wrapper')\n\n    $('select', select_wrapper).attr('disabled', true)\n\n    country_code = $(this).val()\n\n    url = \"/orders/subregion_options?parent_region=#{country_code}\"\n    select_wrapper.load(url)\n```\n\nNow we just need to add a route to `config/routes.rb`:\n\n```ruby\nget '/orders/subregion_options' =\u003e 'orders#subregion_options'\n```\n\nAnd a basic controller action to the appropriate controller:\n\n```ruby\ndef subregion_options\n  render partial: 'subregion_select'\nend\n```\n\nAnd that's basically it. This is obviously a very simple example, but it can\nserve as the foundation of a variety of more involved interactions.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjim%2Fcarmen-demo-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjim%2Fcarmen-demo-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjim%2Fcarmen-demo-app/lists"}