Class: EgovUtils::TownsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/egov_utils/towns_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



3
4
5
6
7
8
9
# File 'app/controllers/egov_utils/towns_controller.rb', line 3

def index
  selected = EgovUtils::Address.towns.lazy.select do |town|
    /\A#{params[:term]}/i.match?(town.name)
  end.first(10)

  render json: { towns: selected.map(&:to_h) }
end