Rails 4.2.0 と Ruby 2.2.0 を使用しています。geokit を使用して、住所を緯度と経度に変換したいと考えています。私はすでに自分の端末に gem install geokit を実行しました。また、Gemfile に gem 'geokit' を含め、bundle install を実行しました。
コントローラーで、関数 Geokit::Geocoders::GoogleGeocoder.geocode() を使用しようとしました。
このように使用すると、次のエラーが発生しました: uninitialized constant 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