rails error with geocoder, geocomplete and double nested form

216 views Asked by At

I am using geocoder and geocomplete. I have haml code in registration/new view

   = f.fields_for :profile do |p|
    = p.fields_for :location, Location.new do |build|
     = build.text_field :address ,:id => 'geo-input-address'

Its generating html:

<input id="geo-input-address" name="user[profile_attributes][location_attributes][address]" type="text" data-validate="true">

In my application.haml

  %script{"type"=>"text/javascript","src"=>"http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"}

in application.js

$("#geo-input-address").geocomplete();

but it is giving error in console when i m running $("#geo-input-address").geocomplete(); in console

Uncaught ReferenceError: google is not defined$.extend.initGeocoder @ jquery.geocomplete.js?body=1:169$.extend.init @ jquery.geocomplete.js?body=1:99GeoComplete @ jquery.geocomplete.js?body=1:91(anonymous function) @ jquery.geocomplete.js?body=1:545jQuery.extend.each @ jquery.js?body=1:384jQuery.fn.jQuery.each @ jquery.js?body=1:137$.fn.geocomplete @ jquery.geocomplete.js?body=1:541(anonymous function) @ VM1842:2InjectedScript._evaluateOn @ VM1841:883InjectedScript._evaluateAndWrap @ VM1841:816InjectedScript.evaluate @ VM1841:682

First of all i am using nested forms.. I am using complex nested form. I have 3 models

Location

class Location < ActiveRecord::Base
  has_many :events
  has_many :profiles
  geocoded_by :address
end

Profile

class Profile < ActiveRecord::Base
  belongs_to :user
  accepts_nested_attributes_for :user
  belongs_to :location
  accepts_nested_attributes_for :location
end

User (Devise)

class User < ActiveRecord::Base
  has_one :profile, dependent: :destroy
  accepts_nested_attributes_for :profile
end

Any idea, please help

0

There are 0 answers