Skip to content

Instantly share code, notes, and snippets.

@farooqyousuf
Created March 22, 2013 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farooqyousuf/5223591 to your computer and use it in GitHub Desktop.
Save farooqyousuf/5223591 to your computer and use it in GitHub Desktop.
<%= gmaps4rails(@json) %>
<%= form_tag places_path, :method => :get do %>
<%= text_field_tag :search, params[:search], placeholder: "Enter your zipcode or city", class: "search-query"%>
<%= submit_tag "Search Nearby", :name => nil, class: "btn btn-flat"%>
<% end %>
class Place < ActiveRecord::Base
acts_as_gmappable For Google Maps
#For Google Maps
def gmaps4rails_address
"#{address}, #{city}, #{state}, #{zipcode}"
end
geocoded_by :complete_address
after_validation :geocode, :if => :check_address_changed?
def complete_address
[address, city, state, zipcode].compact.join(', ')
end
def check_address_changed?
attrs = %w(address city state zipcode)
attrs.any?{|a| send "#{a}_changed?"}
end
end
def index
if params[:search].present?
@places = Place.near(params[:search], 100, :order => :distance).paginate(:page => params[:page], :per_page => 10)
else
@places = Place.scoped.paginate(:page => params[:page], :per_page => 10)
end
@restaurants = @places.where("category = ?", "Restaurant")
@businesses = @places.where("category = ?", "Business")
@json = @places.to_gmaps4rails For Google Maps
respond_to do |format|
format.html # index.html.erb
format.json { render json: @places }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment