songtianlun
f33fb4d2ba
- Implement pagination for the cities index view. - Add shared pagination partial to reduce code duplication. - Modify arts index view to utilize the new pagination. - Update cities controller to include pagination logic. These updates improve usability by allowing better navigation through larger datasets, ensuring users can easily access and view items across multiple pages.
23 lines
616 B
Ruby
23 lines
616 B
Ruby
class CitiesController < ApplicationController
|
|
def index
|
|
@regions = Region.includes(:countries).order(:name)
|
|
@cities = City.includes(:country, country: :region).active.order(:name)
|
|
|
|
if params[:region]
|
|
@current_region = Region.friendly.find(params[:region])
|
|
@cities = @cities.by_region(@current_region.id)
|
|
end
|
|
|
|
if params[:country]
|
|
@current_country = Country.friendly.find(params[:country])
|
|
@cities = @cities.by_country(@current_country.id)
|
|
end
|
|
|
|
@cities = @cities.page(params[:page]).per(10)
|
|
end
|
|
|
|
def show
|
|
@city = City.friendly.find(params[:id])
|
|
end
|
|
end
|