Region selector and filter better scoped

This commit is contained in:
echarp 2019-04-25 11:25:01 +02:00
parent b617ee1dca
commit 61e67072c0
3 changed files with 8 additions and 6 deletions

View File

@ -6,7 +6,8 @@ class Region < ApplicationRecord
has_many :orgas, dependent: :destroy
default_scope { order :name }
scope :local, ->(*) { where 'url IS NULL OR url = \'\'' }
scope :top, ->(*) { where(region: nil).includes(:regions).reorder :code }
scope :local, ->(*) { where(url: nil).or(Region.where(url: '')) }
scope :region, (lambda do |region|
return if region.nil? || region == 'all' || region.to_i.zero?

View File

@ -1,4 +1,3 @@
-# Choose a region to filter events with
%nav.region_filter
%ul= render partial: '/regions/filter_region',
collection: Region.where(region: nil).includes(:regions)
%ul= render partial: '/regions/filter_region', collection: Region.top

View File

@ -1,3 +1,5 @@
.radios= render partial: '/regions/selector_region',
collection: Region.where(region: nil, url: ''),
-# Select a region for an event or organisation
.radios
= render partial: '/regions/selector_region',
collection: Region.top.local,
locals: { f: f }