Search code examples
ruby-on-rails-3google-mapsgmaps4rails

Gmaps4rails are not updating when address field is changed


I am using Gmaps4rails API. But whenever I update or edit the address, gmaps4rails still points to the old address. I am new to rails, so am not sure what is the mistake.

Below is my Controller.rb file

def show
  if current_user.Company.nil?
    @estate = current_user.estates.find(params[:id])
  else
    @estate = Estate.find(params[:id])
  end

  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @estate }
  end
end

def new
  @@key = params[:user_id]
  @master = @@key
  @estate = Estate.new
  @json = @estate.all.to_gmaps4rails

  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @estate }
  end
end

def edit
  @estate = Estate.find(params[:id])
   @json = @estate.to_gmaps4rails
end

def create
  # @estate = Estate.new(params[:estate])
  if current_user.Company.nil?
    @estate = current_user.estates.build(params[:estate])
  else
    serve = User.find(@@key)
    @estate = Estate.new(params[:estate])
    @estate.user_id = serve.id
    @estate.Mgmt = current_user.Company
  end

  respond_to do |format|
    if @estate.save
      if current_user.Company.nil?
        if @estate.companyemail = ''
        ##  
        else
          EstateMailer.company_confirmation(@estate).deliver
        end
      end

      format.html { redirect_to @estate, notice: 'Property details were successfully updated.' }
      format.json { render json: @estate, status: :created, location: @estate }
    else
      format.html { render action: "new" }
      format.json { render json: @estate.errors, status: :unprocessable_entity }
    end
  end
end

def update
  @estate = Estate.find(params[:id])
  @json = Estate.all.to_gmaps4rails

  respond_to do |format|
    if @estate.update_attributes(params[:estate])
      format.html { redirect_to @estate, notice: 'Property details were successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: "edit" }
      format.json { render json: @estate.errors, status: :unprocessable_entity }
    end
  end
end

Solution

  • Try this as per SO post

    You'll need something like this in your model

     :check_process : true/false (if set to false, geocoding will be made at every save/update)
    
     :checker : string (only if check_process is true), could be a method or a db column boolean
    

    More info here. Remember, Google is your friend.