我正在使用Rails 4.2.0和Ruby 2.2.0。我想使用geokit将地址转换为经度和纬度。我已经在我的终端上安装了gemit。我还在gemfile中加入了gem'geokit',并运行bundle install。如何在rails项目上使用geokit
在控制器上,我尝试使用函数Geokit :: Geocoders :: GoogleGeocoder.geocode()。
当我使用它,这样,我得到这个错误:未初始化不断AnswersController ::地址解析器(我的控制器被称为答案)
当我尝试添加要求“geokit”在控制器的开始,我得到了错误:无法加载这样的文件--geokit。
你知道我能做些什么来解决这个问题吗?
在此先感谢
这里是我的控制器
require 'rubygems'
require 'geokit'
class AnswersController < ApplicationController
before_action :set_answer, only: [:show, :edit, :update, :destroy]
def render_page2
render('page2')
end
def answer_page2
if params[:address_origin] && params[:address_destination]
session[:lat_origin] = Geokit::Geocoders::GoogleGeocoder.geocode(params[:address_origin]).lat
session[:lon_origin] = Geokit::Geocoders::GoogleGeocoder.geocode(params[:address_origin]).lng
session[:lat_destination] = Geokit::Geocoders::GoogleGeocoder.geocode(params[:address_destination]).lat
session[:lon_destination] = Geokit::Geocoders::GoogleGeocoder.geocode(params[:address_destination]).lng
#session[:lat_origin] = 37.793688
#session[:lon_origin] = -122.3958692
#session[:lat_destination] = 37.866437
#session[:lon_destination] = -122.265415
redirect_to '/page3'
else
flash[:message] = "All the questions are required on this page."
redirect_to '/page2'
end
end
end
向我们展示你的代码在'answers_controller.rb'中。 – Victor 2015-04-04 16:32:43