[英]undefined method 'merge_conditions' for geokit-rails
I am playing around with Geokit-Rails (https://github.com/andre/geokit-rails) and I need to find all records within 10 miles of an origin. 我正在玩Geokit-Rails(https://github.com/andre/geokit-rails),我需要查找距原点10英里以内的所有记录。 Here's my error: 这是我的错误:
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>'
I have acts_as_mappable
in Company.rb and I have migrated the columns lat
and lng
into Company. 我在Company.rb中有acts_as_mappable
,并且已将lat
和lng
列迁移到Company中。 Where am I going wrong? 我要去哪里错了?
I just stumbled across this very thing myself. 我本人只是偶然发现了这个东西。
This is totally a 1-minute hack fix, but since it's a relatively harmless method insertion that won't affect much outside of it's scope of use, I just added the method straight into the plugin. 这完全是1分钟的hack修复,但是由于它是一种相对无害的方法插入,在使用范围之外不会带来太大影响,因此我将方法直接添加到了插件中。
merge_conditions is a deprecated ActiveRecord::Base method from rails 2.3.8. merge_conditions是Rails 2.3.8中已弃用的 ActiveRecord :: Base方法。
inserted into app/vendor/plugins/geokit-rails/lib/geokit-rails/acts_as_mappable.rb 插入到app / vendor / plugins / geokit-rails / lib / geokit-rails / 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
I'm not exactly sure what replaced this kind of manual SQL condition chaining (maybe :scopes?), so the geokit code is a little old, but sometimes a 1-minute hack fix is all you need especially when the hack is contained within an older external library... 我不确定是什么替代了这种手动SQL条件链接(也许是:scopes?),因此geokit代码有些陈旧,但是有时只需要1分钟的hack修复程序,尤其是当hack包含在其中时一个较旧的外部库...
I guess I'll find out if the original code calls merge_conditions anywhere else tho. 我想我会找出原始代码是否在其他地方调用merge_conditions。 Maybe I'll take the time to figure out the 'proper' way to update this code if it's still being actively managed. 如果仍在积极管理该代码,也许我会花时间找出更新该代码的“正确”方法。
We're not the only ones experiencing this problem. 我们不是唯一遇到此问题的人。
Gonna have to try myModel.geo_scope like the first comment, bblzzz... 必须像第一个评论一样尝试myModel.geo_scope,bblzzz ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.