任何人都可以帮助让 Simplegeo -ruby 客户端在 Rails 3 应用程序中工作吗?

发布于 2024-10-16 11:33:41 字数 1323 浏览 1 评论 0原文

我已经安装了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼中杀气 2024-10-23 11:33:41

您的 Gemfile 中有 simplegeo gem 吗?您运行过bundle install命令吗?当我遇到这样的错误时,这通常是问题所在。

Do you have the simplegeo gem in your Gemfile? And have you ran bundle install command? This is usually the problem when I've come across errors like this.

木槿暧夏七纪年 2024-10-23 11:33:41

您的图层名为“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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文