From 940f1a8f76ea7d177d85f52e89808c1c1287b86d Mon Sep 17 00:00:00 2001 From: songtianlun Date: Wed, 12 Feb 2025 15:12:23 +0800 Subject: [PATCH] feat: add country filter to cities controller - Introduce filtering of cities by selected country - Retrieve current country using friendly find method - Apply city filtering if country is provided in parameters This change allows users to efficiently filter cities based on the selected country, providing a more tailored experience and encouraging better navigation through the list of cities. --- app/controllers/cities_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/cities_controller.rb b/app/controllers/cities_controller.rb index 4949bac..217a57d 100644 --- a/app/controllers/cities_controller.rb +++ b/app/controllers/cities_controller.rb @@ -15,6 +15,11 @@ class CitiesController < ApplicationController @cities = @cities.by_region(@current_region.id) if @current_region end + if params[:country] + @current_country = Country.friendly.find(params[:country]) + @cities = @cities.by_country(@current_country.id) if @current_country + end + @cities = @cities.page(params[:page]).per(12) respond_to do |format|