title: Rails 3: After_create issue with acts_as_gmappable
body: <p>I built an app that creates a user model and automatically creates a profile model and a location(called living) model using the after_create callback method in the model. The model profile belongs to users, and users has one profile, and the model location belong to profile and profile has one location.</p>
  
  <p>The model called location, use the gem geocoder with the current_ip address of the client machine, to pull out the current location of the user, and then save the address, the latitude and longitude in the same model.</p>
  
  <p>Everything works perfectly and fine, except, when I try to add to the location model, acts_as_gmappable, then during the registration process, the same model is not more automatically created, and this prevent the creation of the database column address and obviously consequently, this will bring to an error of gmapsforails.</p>
  
  <p>How I can use the after_create callback in the profile model, and then automatically create the location model, and its column (longitude, latitude, address, ip_address) and at the same time using after the acts_as_gmappable?</p>
  
  <p>I think it's a problem related with which method is called before: the after_create or the gmapsforrails one...this because, if I cut from my location model the call to acts_as_gmappable, register the user, and after past back in the location model the acts_as_gmappable, everything works fine, and the google map is showed.</p>
  
  <p>Thanks to everyone that could in someway highlight my mind...</p>
  
  <p>(1) THE PROFILE MODEL</p>
  
  <pre><code>class Profile &lt; ActiveRecord::Base
  
    # Setup model relationships (has_many require plural)
    belongs_to :user
    has_one :living
  
    after_create :create_living
  
    accepts_nested_attributes_for :living
  
    # Setup accessible (or protected) attributes for your model
    attr_accessible :registration_ip, :registration_timezone, :registration_address, :registration_address_components, :latitude, :longitude, :living_attributes
  
    # Setup Geocoder routine
    geocoded_by :registration_ip
    after_validation :geocode
  
    reverse_geocoded_by :latitude, :longitude do |obj,results|
      if geo = results.first
        obj.registration_address_components  = ActiveSupport::JSON.encode(geo.address_components)
        obj.registration_address  = geo.address
      end
    end
  
    after_validation :reverse_geocode
  
  end
  </code></pre>
  
  <p>(2) THE LIVING MODEL</p>
  
  <pre><code>class Living &lt; ActiveRecord::Base
  
    # Setup model relationships
    belongs_to :profile
  
    # Setup accessible (or protected) attributes for your model
    attr_accessible :current_ip, :current_timezone, :current_address, :current_address_components,     :latitude, :longitude, :gmaps
  
    geocoded_by :current_ip
    after_validation :geocode, :if =&gt; :current_ip_changed?
  
    reverse_geocoded_by :latitude, :longitude do |obj,results|
      if geo = results.first
        obj.current_address_components  = ActiveSupport::JSON.encode(geo.address_components)
        obj.current_address  = geo.address
      end
    end
  
    after_validation :reverse_geocode, :if =&gt; :current_ip_changed?
  
  
    acts_as_gmappable :lat =&gt; 'glat', :lng =&gt; 'glng', :check_process =&gt; :prevent_geocoding,
                      :address =&gt; "current_address", :normalized_address =&gt; "current_address",
                      :msg =&gt; "Sorry, not even Google could figure out where that is"
  
    def prevent_geocoding
      current_address.blank? || (!latitude.blank? &amp;&amp; !longitude.blank?)
    end
  end
  </code></pre>
  
  <p>NOTE The create_before for the profile is in the user model.
  With this system, everytime that an user register, automatically the app create an user record in the user table, a profile record in the profile table and a living record in the living record.
  Everything works perfectly smooth except when I add the acts_as_gmappable in the living model. At that point, the record in the living model table is not more automatically created, and obviously the google maps will not work because will not find the address in the table of the living model (the living model will be nil).</p>
  
  <p>I was thinking that maybe due to the before_create method used in the model, to add a map to living, i will need to create another model let me say gmapliving that belong to living, but at that point I don't have idea how i could ever access the record saved for the address in the living model table.</p>
  
  <p>Please some suggestions?</p>
  
  <p>Thanks
  Dinuz</p>