Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7642383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:10:33+00:00 2026-05-31T09:10:33+00:00

I built an app that creates a user model and automatically creates a profile

  • 0

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.

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.

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.

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?

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.

Thanks to everyone that could in someway highlight my mind…

(1) THE PROFILE MODEL

class Profile < 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

(2) THE LIVING MODEL

class Living < 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 => :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 => :current_ip_changed?


  acts_as_gmappable :lat => 'glat', :lng => 'glng', :check_process => :prevent_geocoding,
                    :address => "current_address", :normalized_address => "current_address",
                    :msg => "Sorry, not even Google could figure out where that is"

  def prevent_geocoding
    current_address.blank? || (!latitude.blank? && !longitude.blank?)
  end
end

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).

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.

Please some suggestions?

Thanks
Dinuz

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:10:35+00:00Added an answer on May 31, 2026 at 9:10 am

    Because you don’t need geocoding from gmaps4rails, add this option:

    :process_geocoding => false
    

    Everything is explained here: https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Model-Customization

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built an app that plays lots of sounds the easy way: AudioServicesPlaySystemSound(someSoundID);
Maybe theres another solution to this. I built a web app that requires 5-10
I built my qt app so that all the Qt modules it uses are
I have an iphone app that I built based off a tutorial (for a
I'm developing an iPhone app that uses the built-in SQLite database. I'm trying to
I've built a C# .NET app that uses the Adobe ActiveX control to display
I have an asp.net mvc app that is built to run as standard web
I built a Winform app several months ago that schedules appointments for repair techs.
I've successfully built and tested a vb.net app in VS 2008 that uses a
I have inherited an app that generates a large array for every user that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.