Geokit在Ruby on Rails的,问题acts_as_mappable [英] Geokit in Ruby on Rails, problem with acts_as_mappable

查看:287
本文介绍了Geokit在Ruby on Rails的,问题acts_as_mappable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过了相关的问题清单看上去不过,看来我的问题并没有被列入到,因此这里是:

基本上我试图on Rails的环境中使用Geokit了Ruby中,即时通讯不知道我是否安装得当,我已经把它列入了environment.rb文件中(和完成耙分贝:安装),我现在想做到以下几点:

 要求'active_record
需要'geokit

一流的商店和LT;的ActiveRecord :: Base的
    acts_as_mappable
结束
 

Unforunately,当我尝试运行这一点,如果看到它的好了,我得到以下错误:

  C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1959年:在`method_missing的':不确定的地方变量或方法`acts_as_mappable'的#<类别:0x4cd261c> (NameError)
    从C:/用户/埃里卡/文档/ Visual Studio 2008中/项目/ StoreLocator / StoreLocator /应用/型号/ store.rb:5
 

我正在运行的Ruby钢为Visual Studio 2008,我不知道我在做什么错了,因为所有的在线教程,我觉得往往是相当老,做适用于我。任何帮助将大大AP preciated。谢谢!

编辑:(加按本公司要求提供) 以下是我的environment.rb样子

 #一定要重新启动服务器,当你修改这个文件

#指定使用时,供应商/轨不是present的Rails的宝石版
RAILS_GEM_VERSION ='2.3.4',除非定义? RAILS_GEM_VERSION

#引导Rails环境,框架和缺省配置
需要File.join(File.dirname(__ FILE__),'启动')

导轨:: Initializer.run办|配置|
  在配置/环境/ *取precedence在此处规定的#设置。
  #应用程序配置应该进入到config /初始化文件
  # - 该目录中的所有文件.RB自动加载。

  #添加额外的负载路径自己的自定义显示目录
  #config.load_paths + =%W(#{} RAILS_ROOT /演员)

  #指定的宝石,这个应用程序依赖于并将它们与耙宝石安装:安装
  #config.gemBJ
  #config.gem角度来说,Hpricot:版本=> '0.6',:源=> HTTP://$c$c.whytheluckystiff.net
  #config.gemsqlite3的,红宝石:LIB => sqlite3的
  #config.gemAWS-S3:LIB => AWS / S3
  config.gemgeokit
  config.gemym4r

  #只加载这里命名的插件,在给定的顺序(默认是按字母顺序)。
  #:都可以作为一个占位符都没有明确命名的插件
  #config.plugins = [:exception_notification,:ssl_requirement,:全部]

  #跳过框架你不打算使用。要使用Rails的没有数据库,
  #你必须删除的活动记录框架。
  #config.frameworks  -  = [:active_record,:active_resource,:action_mailer]

  #激活应始终运行观察员
  #config.active_record.observers =:cacher的,:garbage_collector,:forum_observer

  #设置Time.zone默认为指定的区域,使活动记录自动转换到该区域。
  #运行耙-D时间寻找时区名称的任务列表。
  config.time_zon​​e ='UTC'

  #默认的语言环境是:连接和配置/区域设置/ * RB,阳明海运所有的翻译是自动加载。
  #config.i18n.load_path + = DIR [Rails.root.join(我的,语言环境,*。{RB,阳明海运}')]
  #config.i18n.default_locale =:德
结束

#这些默认值在GeoKit :: Mappable.distance_to和acts_as_mappable使用
GeoKit :: default_units =:公里
GeoKit :: default_formula =:球

#这是秒的超时值将用于调用地理codeR网络
#服务。对于没有超时可言,注释掉设置。超时单元
#以秒为单位。
#GeoKit ::地理codeRS ::超时= 3

#使用这些设置,如果Web服务调用必须通过代理进行路由。
#这些设置可以是零,如果没有必要的,否则,地址和端口必须是
#填充在最低限度。如果代理需要身份验证,用户名
#和密码,可以同时提供。
GeoKit ::地理codeRS :: proxy_addr =零
GeoKit ::地理codeRS :: proxy_port使用=零
GeoKit ::地理codeRS :: proxy_user =零
GeoKit ::地理codeRS :: proxy_pass =零

#这是你的雅虎应用程序键为雅虎地理codeR。
GeoKit ::地理codeRS ::雅虎='REPLACE_WITH_YOUR_YAHOO_KEY

#这是你的谷歌地图的地理codeR关键。
GeoKit ::地理codeRS ::谷歌='apikey

#这是你的用户名和密码的地理coder.us。
#要使用免费服务,该值可以设置为nil或false。对于
#使用捆绑的帐户,该值应设置的用户名:密码。
GeoKit ::地理codeRS ::地理coder_us = FALSE

#这是您的授权密钥地理coder.ca。
#要使用免费服务,该值可以设置为nil或false。对于
#使用绑一个帐户,将该值设置为从获得的关键
#地理coder.ca。

GeoKit ::地理codeRS ::地理coder_ca = FALSE

#这是在地缘codeRS被称为在故障转移方案的顺序
#如果你只需要使用一个单一的地理codeR,把一个符号到数组中。
#有效的符号是:谷歌:雅虎:美国和:CA。
#请注意,也有使用条款限制如何使用
#各种地理codeRS。请务必阅读了相关的使用条款每个
#地理codeR您要使用。
GeoKit ::地理codeRS :: provider_order = [:谷歌]
 

解决方案

acts_as_mappable 是geokit护栏的一部分。您需要安装geokit-Rails插件。

 脚本/插件安装的git://github.com/andre/geokit-rails.git
 

要检查插件是否正确安装,看看你的Rails应用程序的供应商/ plugins目录下。它应该有一个geokit护栏子目录。它,你会发现所有的插件文件,其他的子目录,包括文件 acts_as_mappable.rb (在厂商\插件\ geokit护栏\ LIB \ geokit护栏)。

如果一切似乎正确安装,尝试添加要求geokit在插件根文件夹中init.rb文件的顶部(供应商\插件\ geokit护栏)。

请务必使修改后重新启动你的应用服务器。

i have looked through the list of related questions however my problem does not seem to be listed and hence here it is:

Basically I'm trying to use Geokit within the Ruby on Rails environment, im not sure if i installed it properly, I have included it within the environment.rb (and done rake db:install) and i'm now trying to do the following:

require 'active_record'
require 'geokit'

class Store < ActiveRecord::Base
    acts_as_mappable
end

Unforunately, when i try to run this and see if its ok, i get the following error:

c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1959:in `method_missing': undefined local variable or method `acts_as_mappable' for #<Class:0x4cd261c> (NameError)
    from C:/Users/Erika/Documents/Visual Studio 2008/Projects/StoreLocator/StoreLocator/app/models/store.rb:5

I am running Ruby in Steel for Visual Studio 2008, i'm not sure what i'm doing wrong as all the online tutorials i find tend to be rather old and done apply to me. Any help would be greatly appreciated. thanks!

Edit: (adding as per Ben's Request) The following is what my environment.rb looks like

# Be sure to restart your server when you modify this file

# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')

Rails::Initializer.run do |config|
  # Settings in config/environments/* take precedence over those specified here.
  # Application configuration should go into files in config/initializers
  # -- all .rb files in that directory are automatically loaded.

  # Add additional load paths for your own custom dirs
  # config.load_paths += %W( #{RAILS_ROOT}/extras )

  # Specify gems that this application depends on and have them installed with rake gems:install
  # config.gem "bj"
  # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
  # config.gem "sqlite3-ruby", :lib => "sqlite3"
  # config.gem "aws-s3", :lib => "aws/s3"
  config.gem "geokit"
  config.gem "ym4r"

  # Only load the plugins named here, in the order given (default is alphabetical).
  # :all can be used as a placeholder for all plugins not explicitly named
  # config.plugins = [ :exception_notification, :ssl_requirement, :all ]

  # Skip frameworks you're not going to use. To use Rails without a database,
  # you must remove the Active Record framework.
  # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

  # Activate observers that should always be running
  # config.active_record.observers = :cacher, :garbage_collector, :forum_observer

  # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
  # Run "rake -D time" for a list of tasks for finding time zone names.
  config.time_zone = 'UTC'

  # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
  # config.i18n.default_locale = :de
end

# These defaults are used in GeoKit::Mappable.distance_to and in acts_as_mappable
GeoKit::default_units = :kms
GeoKit::default_formula = :sphere

# This is the timeout value in seconds to be used for calls to the geocoder web
# services.  For no timeout at all, comment out the setting.  The timeout unit
# is in seconds. 
#GeoKit::Geocoders::timeout = 3

# These settings are used if web service calls must be routed through a proxy.
# These setting can be nil if not needed, otherwise, addr and port must be 
# filled in at a minimum.  If the proxy requires authentication, the username
# and password can be provided as well.
GeoKit::Geocoders::proxy_addr = nil
GeoKit::Geocoders::proxy_port = nil
GeoKit::Geocoders::proxy_user = nil
GeoKit::Geocoders::proxy_pass = nil

# This is your yahoo application key for the Yahoo Geocoder.
GeoKit::Geocoders::yahoo = 'REPLACE_WITH_YOUR_YAHOO_KEY'

# This is your Google Maps geocoder key. 
GeoKit::Geocoders::google = 'apikey'

# This is your username and password for geocoder.us.
# To use the free service, the value can be set to nil or false.  For 
# usage tied to an account, the value should be set to username:password.
GeoKit::Geocoders::geocoder_us = false 

# This is your authorization key for geocoder.ca.
# To use the free service, the value can be set to nil or false.  For 
# usage tied to an account, set the value to the key obtained from
# Geocoder.ca.

GeoKit::Geocoders::geocoder_ca = false

# This is the order in which the geocoders are called in a failover scenario
# If you only want to use a single geocoder, put a single symbol in the array.
# Valid symbols are :google, :yahoo, :us, and :ca.
# Be aware that there are Terms of Use restrictions on how you can use the 
# various geocoders.  Make sure you read up on relevant Terms of Use for each
# geocoder you are going to use.
GeoKit::Geocoders::provider_order = [:google]

解决方案

acts_as_mappable is part of geokit-rails. You need to install the geokit-rails plugin.

script/plugin install git://github.com/andre/geokit-rails.git

To check if the plugin is properly installed, look under the vendor/plugins directory of your Rails app. It should have a geokit-rails sub directory. It it, you'll find all the plugin files, other subdirectories, including the file acts_as_mappable.rb (in vendor\plugins\geokit-rails\lib\geokit-rails).

If everything seems to be properly installed, try adding "require geokit" to the top of the init.rb file in the plugin root folder (vendor\plugins\geokit-rails).

Be sure to restart your app server after making the modifications.

这篇关于Geokit在Ruby on Rails的,问题acts_as_mappable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆