I use Sunspot to find and use Geocoder for addresses, and then to calculate distances, Geokit-rails3 .
class Product < ActiveRecord::Base
belongs_to :store
searchable do
text :name
end
end
class Store < ActiveRecord::Base
acts_as_mappable
geocoded_by :address, :latitude => :lat, :longitude => :lng
attr_accessible :lat, :lng, :address
has_many :products
end
Question
What I want when entering into a product search is also the ability to enter an address inside another field to search for products in this area with a radius of 30 miles.
This is my controller that allows me to search Products:
class SearchController < ApplicationController
def index
@search = Product.search do |q|
q.fulltext params[:search]
end
@products = @search.results
end
end
So, I believe that the form will look something like this as soon as I finish:
<%= form_tag search_path, :method => 'get' do %>
<%= text_field_tag :search, params[:search]" %>
<%= submit_tag "Search", :name => nil %>
<p> Search Near: </p>
<%= label_tag :location, "Search nearby an Address" %>
<%= text_field_tag :location, params[:location] %>
<% end %>
I think it :locationwill serve as a virtual attribute for stores :addressto display the field correctly, but these are all assumptions.
How do I set all this to achieve a specific scenario?