更改地址字段时Gmaps4rails不会更新

时间:2013-07-02 18:07:37

标签: ruby-on-rails-3 google-maps gmaps4rails

我正在使用Gmaps4rails API。但每当我更新或编辑地址时,gmaps4rails仍指向旧地址。我是rails的新手,所以不确定是什么错误。

以下是我的Controller.rb文件

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

1 个答案:

答案 0 :(得分:0)

根据SO post

尝试此操作

你的模型中需要这样的东西

 :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

更多信息here。请记住,Google是您的朋友。