diff --git a/app/controllers/my_profile/maps_controller.rb b/app/controllers/my_profile/maps_controller.rb index a8ac94a..1d8b5d2 100644 --- a/app/controllers/my_profile/maps_controller.rb +++ b/app/controllers/my_profile/maps_controller.rb @@ -31,23 +31,11 @@ class MapsController < MyProfileController end def search_city - - term = params[:term]; - - regions = NationalRegion.search_city(term + "%", true).map {|r|{ :label => r.city , :category => r.state}} - - render :json => regions - + render :json => MapsHelper.search_city(params[:term]) end def search_state - - term = params[:term]; - - regions = NationalRegion.search_state(term + "%", true).map {|r|{ :label => r.state}} - - render :json => regions - + render :json => MapsHelper.search_state(params[:term]) end end diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index 4a64230..73171a0 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -291,6 +291,23 @@ class AccountController < ApplicationController render :text => user_data.to_json, :layout => false, :content_type => "application/javascript" end + def search_cities + if request.xhr? and params[:state_name] and params[:city_name] + render :json => MapsHelper.search_city(params[:city_name], params[:state_name]) + else + render :json => [].to_json + end + end + + def search_state + if request.xhr? and params[:state_name] + render :json => MapsHelper.search_state(params[:state_name]) + else + render :json => [].to_json + end + end + + protected def redirect? diff --git a/app/helpers/maps_helper.rb b/app/helpers/maps_helper.rb new file mode 100644 index 0000000..93d9387 --- /dev/null +++ b/app/helpers/maps_helper.rb @@ -0,0 +1,14 @@ +module MapsHelper + def self.search_city term, state="" + cities = if state.empty? + NationalRegion.search_city(term + "%", true) + else + NationalRegion.search_city(term + "%", true, state) + end + cities.map {|r|{ :label => r.city , :category => r.state}} + end + + def self.search_state term + NationalRegion.search_state(term + "%", true).map {|r|{ :label => r.state}} + end +end diff --git a/app/models/national_region.rb b/app/models/national_region.rb index e06e4ba..6990986 100644 --- a/app/models/national_region.rb +++ b/app/models/national_region.rb @@ -12,7 +12,7 @@ class NationalRegion < ActiveRecord::Base adtional_contions = ""; if like - operator = "like" + operator = "ilike" find_return = :all end @@ -41,7 +41,7 @@ class NationalRegion < ActiveRecord::Base find_return = :first if like - operator = "like" + operator = "ilike" find_return = :all end diff --git a/app/views/profile_editor/_person_form.rhtml b/app/views/profile_editor/_person_form.rhtml index 336ae7a..4c8a2f8 100644 --- a/app/views/profile_editor/_person_form.rhtml +++ b/app/views/profile_editor/_person_form.rhtml @@ -19,8 +19,8 @@ <%= optional_field(@person, 'birth_date', labelled_form_field(_('Birth date'), '