Sinatra 응용 프로그램에서 DataMapper 모델과 함께 Geocoder gem을 사용하려고합니다.Sinatra 및 DataMapper와 함께 Geocoder 사용
environment.rb
:
require 'rubygems'
require 'bundler/setup'
require 'dm-core'
require 'dm-timestamps'
require 'dm-validations'
require 'dm-aggregates'
require 'dm-migrations'
require 'dm-types'
require 'geocoder'
require 'sinatra' unless defined?(Sinatra)
# load models
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib")
Dir.glob("#{File.dirname(__FILE__)}/lib/*.rb") { |lib| require File.basename(lib, '.*') }
DataMapper.setup(:default, (ENV["DATABASE_URL"] || "sqlite3:///#{File.expand_path(File.dirname(__FILE__))}/#{Sinatra::Base.environment}.db"))
DataMapper.finalize
DataMapper.auto_upgrade!
lib/location.rb
:
class Location
include DataMapper::Resource
include Geocoder::Model::Base
property :id, Serial
property :address, String, :required => true
# geocoder gem
geocoded_by :address, :latitude => :lat, :longitude => :lng
# geocoder
after_validation :geocode, :if => :address_changed?
end
내가 IRB 세션을 시작하려고
, 예외가 생성됩니다 내가 이해하고 있지 않다 무엇irb> require './environment'
NameError: uninitialized constant Geocoder::Model
...
?
@craig 편집 해 주셔서 감사합니다! – Kashyap