Local regions can now be listed in json

remotes/origin/master
echarp 5 years ago
parent 2ee90cd937
commit c960760964
  1. 10
      app/controllers/regions_controller.rb
  2. 1
      app/models/region.rb
  3. 3
      app/views/regions/index.json.jbuilder

@ -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

@ -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

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