Created
March 22, 2013 18:25
-
-
Save farooqyousuf/5223591 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
<%= 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 %> |
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
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 | |
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 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