Local regions can now be listed in json

This commit is contained in:
echarp 2018-03-18 16:32:59 +01:00
parent 2ee90cd937
commit c960760964
3 changed files with 13 additions and 1 deletions

View File

@ -1,4 +1,12 @@
# Manage regions, mostly get stats out of them
class RegionsController < InheritedResources::Base
class RegionsController < ApplicationController
has_scope :region
before_action :set_regions, only: [:index]
private
def set_regions
@regions = apply_scopes Region.local
end
end

View File

@ -6,6 +6,7 @@ class Region < ApplicationRecord
has_many :orgas, dependent: :destroy
default_scope { order :name }
scope :local, ->(*) { where url: nil }
scope :region, (lambda do |region|
return if region.nil? || region == 'all' || region.to_i.zero?
temp = Region.find region

View File

@ -0,0 +1,3 @@
json.array!(@regions) do |region|
json.extract! region, :id, :region_id, :name, :code
end