2011-06-20 48 views
2

我在玩Geokit-Rails(https://github.com/andre/geokit-rails),我需要找到距離原點10英里範圍內的所有記錄。這是我的錯誤:未定義方法'merge_conditions'爲geokit-rails

Company.find(:all, :origin=>'New York, NY', :within=>10) 
NoMethodError: undefined method `merge_conditions' for #<Class:0x0000010832f740> 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.1/lib/active_record/base.rb:1016:in 'method_missing' 
from /Users/san/Documents/sanj/app/vendor/plugins/geokit-rails/lib/geokit-rails/acts_as_mappable.rb:349:in `apply_bounds_conditions' 
from /Users/san/Documents/sanj/app/vendor/plugins/geokit-rails/lib/geokit-rails/acts_as_mappable.rb:260:in `prepare_for_find_or_count' 
from /Users/san/Documents/sanj/app/vendor/plugins/geokit-rails/lib/geokit-rails/acts_as_mappable.rb:152:in `find' 
from (irb):4 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:44:in `start' 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:8:in `start' 
from /Users/san/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands.rb:23:in `<top (required)>' 
from script/rails:6:in `require' 
from script/rails:6:in `<main>' 

我在Company.rb acts_as_mappable,我已經遷移列latlng到公司。我哪裏錯了?

回答

5

我剛剛偶然發現了這件事。

這完全是1分鐘的破解修復,但由於它是一個相對無害的方法插入,它不會影響很多使用範圍,所以我只是直接將該方法添加到插件中。

merge_conditions是一個deprecated來自rails 2.3.8的ActiveRecord :: Base方法。

插入到應用程序/供應商/插件/ geokit護欄/ lib目錄/ geokit護欄/ acts_as_mappable.rb

private 
    def merge_conditions(*conditions) 
    segments = [] 

    conditions.each do |condition| 
     unless condition.blank? 
     sql = sanitize_sql(condition) 
     segments << sql unless sql.blank? 
     end 
    end 

    "(#{segments.join(') AND (')})" unless segments.empty? 
    end 

我不完全知道什麼代替這種手工SQL條件鏈(可能: ),所以geokit代碼有點舊了,但有時候只需要1分鐘的破解修復,特別是當破解包含在一個較舊的外部庫中時...

我想我會發現如果原始代碼在其他任何地方調用merge_conditions。也許我會花時間找出更新此代碼的「正確」方式,如果它仍然被主動管理。

我們是not the only ones遇到此問題。

必須嘗試myModel.geo_scope喜歡第一個評論,bblzzz ...