【发布时间】:2015-04-04 16:28:40
【问题描述】:
我正在使用 Rails 4.2.0 和 Ruby 2.2.0。我想使用 geokit 将地址转换为纬度和经度。我已经在终端中安装了geokit。我还在我的 Gemfile 中包含 gem 'geokit',然后运行 bundle install。
在控制器上,我尝试使用函数 Geokit::Geocoders::GoogleGeocoder.geocode()。
当我像这样使用它时,我得到了这个错误:未初始化的常量 AnswersController::Geocoders(我的控制器称为 Answers)
当我尝试在控制器开头添加 require '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向我们展示您的代码。
标签: ruby-on-rails ruby geokit