module ZipSearch::ActsAsLocation::ClassMethods
Public Instance Methods
acts_as_location(title=:location, options={})
click to toggle source
# File lib/zip_search/acts_as_location.rb, line 13 def acts_as_location(title=:location, options={}) pg_search_scope :search_by_location, against: [:zip, :county, :city, :state], using: {tsearch: {prefix: true}} pg_search_scope :search_by_state, against: :state, using: {tsearch: {prefix: true}} pg_search_scope :search_by_city, against: :city, using: {tsearch: {prefix: true}} pg_search_scope :search_by_county, :against => :county, using: {tsearch: {prefix: true}} pg_search_scope :search_by_zip, against: :zip geocoded_by :to_sentence reverse_geocoded_by :latitude, :longitude do |obj, results| if geo = results.first obj.street_address ||= obj.street_address obj.zip ||= geo.postal_code obj.county ||= geo.county if geo.respond_to? :county obj.city ||= geo.city obj.state ||= geo.state end end after_validation :geocode, if: :should_geocode? after_validation :reverse_geocode, if: :should_reverse_geocode? validates_presence_of :zs_association_name include ActsAsLocation::LocalInstanceMethods end
location_fields()
click to toggle source
# File lib/zip_search/acts_as_location.rb, line 43 def location_fields; %i( street_address zip county city state ) end
nested_params(extra_params=[])
click to toggle source
# File lib/zip_search/acts_as_location.rb, line 50 def nested_params(extra_params=[]) [:id, :_destroy] + params(extra_params) end
params(extra_params=[])
click to toggle source
# File lib/zip_search/acts_as_location.rb, line 45 def params(extra_params=[]) extra_params + [ :zs_association_name, :title, :latitude, :longitude, :street_address, :zip, :county, :city, :state ] end