任何人都可以帮助让 Simplegeo -ruby 客户端在 Rails 3 应用程序中工作吗?
我已经安装了 simplegeo-ruby gem 并能够通过 Rails 控制台使其正常工作,使用这些命令成功创建记录:(
注意 - 我首先通过 geokit 和 Google 查找地址)
>> @record = Record.new(:address => 'Address')
>> geocoded = Geokit::Geocoders::GoogleGeocoder.geocode @record.address
record = SimpleGeo::Record.new({
:id => @record.id,
:created => Time.now,
:lat => geocoded.lat,
:lon => geocoded.lng,
:layer => 'com.mylayer.records',
})
>> SimpleGeo::Client.add_record(record)
但是,当尝试创建新记录并抛出此错误时,我的应用程序崩溃了:
SimpleGeo::NotFound
app/controllers/records_controller.rb:24:in `create'
我的 RecordsController#create 操作如下所示:
def create
@record = Record.new(params[:record])
geocoded = Geokit::Geocoders::GoogleGeocoder.geocode @record.address
record = SimpleGeo::Record.new({
:id => @record.id,
:created => Time.now,
:lat => geocoded.lat,
:lon => geocoded.lng,
:layer => 'com.mylayer.records',
})
SimpleGeo::Client.add_record(record)
if @record.save
flash[:notice] = "Successfully created record."
redirect_to @record
else
render :action => 'new'
end
end
非常感谢任何使用 Simplegeo 和 Rails 3 的帮助或参考。
I have installed the simplegeo-ruby gem and have been able to get this working through the Rails console, successfully creating records with the these commands:
(Note - I'm looking up the address via geokit and Google first)
>> @record = Record.new(:address => 'Address')
>> geocoded = Geokit::Geocoders::GoogleGeocoder.geocode @record.address
record = SimpleGeo::Record.new({
:id => @record.id,
:created => Time.now,
:lat => geocoded.lat,
:lon => geocoded.lng,
:layer => 'com.mylayer.records',
})
>> SimpleGeo::Client.add_record(record)
However my app is breaking when attempting to create a new record and throwing this error:
SimpleGeo::NotFound
app/controllers/records_controller.rb:24:in `create'
My RecordsController#create action looks like this:
def create
@record = Record.new(params[:record])
geocoded = Geokit::Geocoders::GoogleGeocoder.geocode @record.address
record = SimpleGeo::Record.new({
:id => @record.id,
:created => Time.now,
:lat => geocoded.lat,
:lon => geocoded.lng,
:layer => 'com.mylayer.records',
})
SimpleGeo::Client.add_record(record)
if @record.save
flash[:notice] = "Successfully created record."
redirect_to @record
else
render :action => 'new'
end
end
Any help or references using Simplegeo with Rails 3 are much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
Gemfile
中有 simplegeo gem 吗?您运行过bundle install
命令吗?当我遇到这样的错误时,这通常是问题所在。Do you have the simplegeo gem in your
Gemfile
? And have you ranbundle install
command? This is usually the problem when I've come across errors like this.您的图层名为“com.mylayer.records”吗?这通常只是一个示例层。
在这里创建您自己的图层:http://simplegeo.com/layers
如果您看不到该页面,那么您就不会无法访问 SimpleGeo Storage 的私人测试版。不过,它应该会在几个月内公开。
如果您想对美国的地址进行地理编码,请使用 SimpleGeo 的 /1.0/context 端点: http://simplegeo.com/docs/api-endpoints/simplegeo-context#get-context
Is your layer called "com.mylayer.records"? That is usually just an example layer.
Create your own layers here: http://simplegeo.com/layers
If you cannot see that page, then you don't have access to the private beta of SimpleGeo Storage. It should be in the public in a few months though.
If you want to geocode addresses in the US, use SimpleGeo's /1.0/context endpoint: http://simplegeo.com/docs/api-endpoints/simplegeo-context#get-context