I installed gmaps4rails in my application.
The view related stuff seems to be working, since the an empty google maps shows up. So I am thinking that I installed it correctly.
I followed the quick start on the github page:
My controller:
def map
@businesses = Business.all
@json = @businesses.to_gmaps4rails
respond_to do |format|
format.html
format.json {render json:@businesses}
end
end
My view:
=gmaps4rails(@json)
=@json
I print @json and realized that the value is empty i.e. []
My business.rb model:
class Business < ActiveRecord::Base
belongs_to :city
belongs_to :category
has_many :reviews
attr_accessible :address, :description, :name, :phone, :urbanization, :url, :city_id
include FriendlyId
friendly_id :name, :use => :slugged
acts_as_gmappable
def gmaps4rails_address
# "#{self.address}, #{self.urbanization}, #{self.city.name}"
"619 Johnson Street, Kingston, ON"
end
end
I hard coded the address for testing...
Gmaps4rails doesn't geocode on the fly for performance concerns.
to_gmaps4rails returns empty json if objects don't have lat or long.
You should preprocess your objects (simply save them).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With