Update city_cache.rb
This commit is contained in:
		
							parent
							
								
									0ffdc6e9ad
								
							
						
					
					
						commit
						80000057a6
					
				| @ -3,11 +3,19 @@ class CityCache < ActiveRecord::Base | ||||
| 
 | ||||
|   belongs_to :city | ||||
| 
 | ||||
|   # look for a term to see if its already been searched for | ||||
|   def self.search(str) | ||||
|     CityCache.find_by_search(str.downcase) | ||||
|     CityCache.find_by_search(normalize_string(str)) | ||||
|   end | ||||
| 
 | ||||
|   # cache this search term | ||||
|   def self.cache(str, city_id) | ||||
|   	CityCache.create(city_id: city_id, search: str.downcase) | ||||
|   	CityCache.create(city_id: city_id, search: normalize_string(str)) | ||||
|   end | ||||
|    | ||||
|   private | ||||
|     def normalize_string(str) | ||||
|       # remove accents, unnecessary whitespace, punctuation, and lowcase tje string | ||||
|       I18n.transliterate(str).gsub(/[^\w\s]/, '').gsub(/\s\s+/, ' ').strip.downcase | ||||
|     end | ||||
| end | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user