Created
June 13, 2013 16:49
-
-
Save milushov/5775344 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def check_location_type | |
if types = params['search2'].try{|x| x['location_types']} | |
unless (valid_types = types.keys.select{|k| k.to_i >= 1 && k.to_i <= 5}).empty? | |
models = { 2 => Region, 3 => City, 4 => MunRegion, 5 => Road } | |
valid_types.each do |id| | |
ids = types[id].split(',').map(&:to_i) | |
if id == '1' | |
@realty_objects = @realty_objects.joins(:location => :metro_stations) | |
.where('locations_metro_stations.metro_station_id in (?)', ids) | |
else | |
model = models[id.to_i] | |
field = model.table_name[0..-2] + '_id' | |
locations_ids = Location.where(field => ids).map{|loc| loc.id} | |
@realty_objects = @realty_objects.where id: locations_ids | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment