diff --git a/app/controllers/country_states_controller.rb b/app/controllers/countries_states_controller.rb similarity index 71% rename from app/controllers/country_states_controller.rb rename to app/controllers/countries_states_controller.rb index 9a9484ec6..096a7c4fb 100644 --- a/app/controllers/country_states_controller.rb +++ b/app/controllers/countries_states_controller.rb @@ -1,4 +1,4 @@ -class CountryStatesController < ApplicationController +class CountriesStatesController < ApplicationController skip_before_action :authenticate_user! skip_verify_authorized only: %i[index] @@ -8,7 +8,7 @@ def index @name = params[:name] @selected_state = params[:province_state] - @states = CS[country.to_sym][:states].invert + @states = COUNTRIES_STATES[country.to_sym][:states].invert respond_to do |format| format.turbo_stream diff --git a/app/controllers/organizations/staff/organizations_controller.rb b/app/controllers/organizations/staff/organizations_controller.rb index ac8a497d2..0f92ef0b3 100644 --- a/app/controllers/organizations/staff/organizations_controller.rb +++ b/app/controllers/organizations/staff/organizations_controller.rb @@ -6,6 +6,7 @@ class OrganizationsController < Organizations::BaseController before_action :set_organization, only: %i[edit update] def edit + @location = @organization.locations.last || @organization.locations.build # polymorphic end def update diff --git a/app/views/country_states/index.turbo_stream.erb b/app/views/countries_states/index.turbo_stream.erb similarity index 100% rename from app/views/country_states/index.turbo_stream.erb rename to app/views/countries_states/index.turbo_stream.erb diff --git a/app/views/organizations/staff/organizations/_form.html.erb b/app/views/organizations/staff/organizations/_form.html.erb index 6ce2493b1..0e808198e 100644 --- a/app/views/organizations/staff/organizations/_form.html.erb +++ b/app/views/organizations/staff/organizations/_form.html.erb @@ -39,9 +39,8 @@
-
- <% location = organization.locations.last || organization.locations.build %> - <%= form.fields_for :locations, location do |location_form| %> +
+ <%= form.fields_for :locations, @location do |location_form| %> <%= render 'shared/location_fields', form: location_form %> <% end %>
diff --git a/app/views/shared/_location_fields.html.erb b/app/views/shared/_location_fields.html.erb index f5cae6e38..89da415c0 100644 --- a/app/views/shared/_location_fields.html.erb +++ b/app/views/shared/_location_fields.html.erb @@ -1,9 +1,9 @@ <%= form.select :country, - CS.keys.index_with { |abbr| CS.dig(abbr, :name) }.invert, + COUNTRIES_STATES.keys.index_with { |abbr| COUNTRIES_STATES.dig(abbr, :name) }.invert, { prompt: "Please select" }, { - 'data-path': country_states_path, + 'data-path': countries_states_path, 'data-country-state-target': 'country', 'data-action': 'change->country-state#updateStates', required: true, @@ -12,7 +12,7 @@ <%= form.select :province_state, form.object.country.present? ? - CS.dig(form.object.country.to_sym, :states)&.map { |abbr, name| [:name, abbr] } : [], + COUNTRIES_STATES.dig(form.object.country.to_sym, :states)&.map { |abbr, name| [:name, abbr] } : [], { prompt: "Please select" }, { 'data-country-state-target': 'state', diff --git a/config/initializers/countries_states.rb b/config/initializers/countries_states.rb index bfea4e3b6..3096b495a 100644 --- a/config/initializers/countries_states.rb +++ b/config/initializers/countries_states.rb @@ -1,6 +1,6 @@ begin - CS = YAML.safe_load_file(Rails.root.join("config/countries_states.yml"), symbolize_names: true).freeze + COUNTRIES_STATES = YAML.safe_load_file(Rails.root.join("config/countries_states.yml"), symbolize_names: true).freeze rescue => e puts "Error loading countries_states.yml: #{e.message}" - CS = {}.freeze + COUNTRIES_STATES = {}.freeze end diff --git a/config/routes.rb b/config/routes.rb index e341873c7..be3fa6e53 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,7 +9,7 @@ } # Application Scope - resources :country_states, only: [:index] + resources :countries_states, only: [:index] root "root#index" get "/up", to: "root#up" # Health check endpoint to let Kamal know the app is up diff --git a/test/controllers/country_states_controller_test.rb b/test/controllers/country_states_controller_test.rb index 1d94650b4..67b6b7385 100644 --- a/test/controllers/country_states_controller_test.rb +++ b/test/controllers/country_states_controller_test.rb @@ -1,6 +1,6 @@ require "test_helper" -class CountryStatesControllerTest < ActionDispatch::IntegrationTest +class CountriesStatesControllerTest < ActionDispatch::IntegrationTest test "should return turbo stream with the states in it" do adopter = create(:adopter) sign_in adopter @@ -8,7 +8,7 @@ class CountryStatesControllerTest < ActionDispatch::IntegrationTest name = "adopter[address_attributes][state]" target = "adopter_foster_profile_location_attributes_province_state" - get country_states_path, + get countries_states_path, headers: {"Accept" => "text/vnd.turbo-stream.html"}, params: {country: "CA", target:, name:, province_state: "BC"}