2009-11-15 29 views
1

問題我已經通過相關的問題清單看着然而我的問題似乎並沒有上市,因此在這裏它是:Geokit在Ruby on Rails的,與acts_as_mappable

基本上我試圖內使用Geokit Ruby on Rails的環境中,即時通訊不知道我是否正確安裝了它,我的environment.rb文件中包含它(和做耙分貝:安裝),現在我正在努力做到以下幾點:

require 'active_record' 
require 'geokit' 

class Store < ActiveRecord::Base 
    acts_as_mappable 
end 

Unforunately ,當我嘗試運行這個,看看它的好,我得到以下錯誤:

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 

我在Visual Studio 2008中運行Ruby in Steel,我不確定我在做什麼錯誤,因爲我發現所有在線教程都傾向於比較陳舊並且適用於我。任何幫助將不勝感激。謝謝!

編輯:(添加爲每本的請求) 以下是我的environment.rb看起來像

# 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] 
你用什麼樣的方式包括geokit圖書館

回答

2

acts_as_mappable是geokit-rails的一部分。您需要安裝geokit-rails插件。

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

要檢查插件是否安裝正確,請查看您的Rails應用程序的vendor/plugins目錄。它應該有一個geokit-rails子目錄。它,你會發現所有的插件文件,其他子目錄,包括文件acts_as_mappable.rb(在vendor\plugins\geokit-rails\lib\geokit-rails)。

如果一切似乎都已正確安裝,請嘗試將"require geokit"添加到插件根文件夾(vendor\plugins\geokit-rails)中init.rb文件的頂部。

確保在進行修改後重新啓動您的應用服務器。

+0

哦,jeez你是對的。我使用插件,甚至沒有考慮寶石的作用。仍然主要困惑於'require'active_record「'業務。 – Ben 2009-11-15 23:28:02

+0

當我安裝它時,它告訴我它已經安裝好了,除了安裝它之外,我應該做些別的事嗎?也許它會讓它與其他地理工具包混淆?在嘗試和重新嘗試之後,非常感謝幫助 – Erika 2009-11-16 00:00:58

+0

,肯定會有一些問題。當我嘗試安裝上述插件時,它一直說「插件未找到:[]」當我用--trace運行它時。有任何想法嗎? – Erika 2009-11-16 01:12:47

0

?該插件?寶石?寶石是否解包到供應商?你的environment.rb是什麼樣的?

編輯:我打算留下這個問題作爲評論 - 請原諒我。

+0

我在項目文件夾中添加了項目的寶石,然而供應商文件是空的。我已經更新了我的帖子,以添加有關environment.rb的詳細信息,這些信息非常空。非常感謝您的幫助 – Erika 2009-11-15 22:25:36

+0

我看到的唯一不尋常的事情是,將這與我的一些項目相比較,是您需要在模型文件中使用activerecord和geokit - 這是不必要的,並且可能會導致併發症。刪除這兩行,然後重試。如果這不起作用,請嘗試做耙寶石:解包給供應商你的寶石。 – Ben 2009-11-15 22:34:59

+0

謝謝,我做了耙寶石:解壓,然而在模型文件中,如果我沒有指定「需要....」,那麼甚至不識別activerecord。我還添加了一些代碼給我的environment.rb(另一個編輯)。我仍然遺憾地失去了:s – Erika 2009-11-15 23:01:13