mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Zones were intended to be sorted by name. But I guess that the syntax of Ransack changed one day and we didn't notice because the spec was creating entries in the right order already (which often reflects the query result order without parameters). So the spec is fixed to fail if the sorting doesn't happen and Ransack is configured to sort correctly. The previous sort value was ignored.
41 lines
943 B
Ruby
41 lines
943 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Spree
|
|
module Admin
|
|
class ZonesController < ::Admin::ResourceController
|
|
before_action :load_data, except: [:index]
|
|
|
|
def new
|
|
@zone.zone_members.build
|
|
end
|
|
|
|
protected
|
|
|
|
def collection
|
|
params[:q] ||= {}
|
|
params[:q][:s] ||= "name asc"
|
|
@search = super.ransack(params[:q])
|
|
@pagy, @zones = pagy(@search.result, items: Spree::Config[:orders_per_page])
|
|
@zones
|
|
end
|
|
|
|
def load_data
|
|
@countries = Country.order(:name)
|
|
@states = State.order(:name)
|
|
@zones = Zone.order(:name)
|
|
end
|
|
|
|
def permitted_resource_params
|
|
params.require(:zone).permit(
|
|
:name, :description, :default_tax, :kind,
|
|
zone_members_attributes: [:id, :zoneable_id, :zoneable_type, :_destroy]
|
|
)
|
|
end
|
|
|
|
def location_after_save
|
|
edit_object_url(@zone)
|
|
end
|
|
end
|
|
end
|
|
end
|