module EgovUtils class TownsController < ApplicationController 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 end end