Jngai1297
Jngai1297

Reputation: 2495

Using Gmap4Rails Gem No Error but Map is not getting displayed

Hi I am currently going through this tutorial using gmap4rails

http://andyglassblog.wordpress.com/2012/07/06/google-maps-for-rails-with-gmaps4-rails-tutorial-on-how-to-post-and-filter-locations/

I am quite new to this gem so I am just going through the guide step by step.

I have a cities_controller.rb

 class CitiesController < ApplicationController
        def index
        @cities = City.all
        @json = @cities.to_gmaps4rails
        end
    end 

I have a city.rb for my model

class City < ActiveRecord::Base 
    acts_as_gmappable

    has_many :neighborhoods 

    def gmaps4rails_address
        "#{self.name}, #{self.state}"
    end

end 

This is my index.html.erb within my cities folder inside my view folder

<%= gmaps4rails(@json) %>

I added the gem ran the installer as well.

In my application layout, I have this in my body

<%= yield :scripts %>

This is my schema

 ActiveRecord::Schema.define(version: 20130714194244) do

      create_table "cities", force: true do |t|
        t.string   "name"
        t.string   "state"
        t.float    "latitude"
        t.float    "longitude"
        t.boolean  "gmaps"
        t.datetime "created_at"
        t.datetime "updated_at"
        t.integer  "population"
      end

I am actually getting no errors, I seeded the database with these

  City.create(name: "New york" ,state: "NY", population: 8175133)
    City.create(name: "Los Angeles",state: "CA", population: 3792621 )
    City.create(name: "Chicago",state: "IL", population: 2695598)
    City.create(name: "Houston",state: "TX", population: 2099451)
    City.create(name: "Philadelphia",state: "PA" , population: 1526006)
    City.create(name: "Phoenix",state: "AZ", population: 1445632)
    City.create(name: "San Antonio",state: "TX", population: 1327407)
    City.create(name: "San Diego",state: "CA", population: 1307402 )
    City.create(name: "Dallas",state: "TX", population: 1197816)
    City.create(name: "San Jose",state: "CA", population: 945942)

When I open my rails console and do City.all

I noticed that the latitude and longitude has been calculated for me which means the gem is working properly.

#<City id: 1, name: "New york", state: "NY", latitude: 40.7143528, longitude: -74.00597309999999, gmaps: true, created_at: "2013-07-14 19:51:32", updated_at: "2013-07-14 19:51:32", population: 8175133>

Am I missing some api key? when I do rails s all I get is a blank screen? At the minimum I should be seeing a map. It could be a js problem, I am not quite sure.

Thanks!

Upvotes: 1

Views: 420

Answers (1)

Jngai1297
Jngai1297

Reputation: 2495

Don't use gmaps4rails with rails 4.0 yet, there is a turbolink issue. Multiple users are having rails 4.0 problems on the issues page on gmaps4rails repo. The js files were generated into my public folder when I ran the generate command using rails 4. I switched back to 3.2.13 and ruby 1.9.3p429 now the js files are getting generated in my assets folder.

Upvotes: 1

Related Questions