Local regions can now be listed in json
This commit is contained in:
parent
2ee90cd937
commit
c960760964
@ -1,4 +1,12 @@
|
|||||||
# Manage regions, mostly get stats out of them
|
# Manage regions, mostly get stats out of them
|
||||||
class RegionsController < InheritedResources::Base
|
class RegionsController < ApplicationController
|
||||||
has_scope :region
|
has_scope :region
|
||||||
|
|
||||||
|
before_action :set_regions, only: [:index]
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_regions
|
||||||
|
@regions = apply_scopes Region.local
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,6 +6,7 @@ class Region < ApplicationRecord
|
|||||||
has_many :orgas, dependent: :destroy
|
has_many :orgas, dependent: :destroy
|
||||||
|
|
||||||
default_scope { order :name }
|
default_scope { order :name }
|
||||||
|
scope :local, ->(*) { where url: nil }
|
||||||
scope :region, (lambda do |region|
|
scope :region, (lambda do |region|
|
||||||
return if region.nil? || region == 'all' || region.to_i.zero?
|
return if region.nil? || region == 'all' || region.to_i.zero?
|
||||||
temp = Region.find region
|
temp = Region.find region
|
||||||
|
3
app/views/regions/index.json.jbuilder
Normal file
3
app/views/regions/index.json.jbuilder
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
json.array!(@regions) do |region|
|
||||||
|
json.extract! region, :id, :region_id, :name, :code
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user