简体   繁体   English

geokit-rails的未定义方法'merge_conditions'

[英]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 ,并且已将latlng列迁移到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.

相关问题 未定义的方法&#39;distance_betwwen&#39;geokit-rails - undefined method `distance_betwwen' geokit-rails 在模型实例方法中使用Geokit-Rails时出错 - Error while using Geokit-Rails in model instance method Geokit-Rails:多态位置查询 - Geokit-Rails: polymorphic location query Geokit-rails新设置,找不到表“ locations” Rails 5 - Geokit-rails fresh setup, Could not find table 'locations' Rails 5 如果geokit-rails不再具有geo_scope方法,我应该用来获取地址的经纬度 - If geokit-rails no longer has geo_scope method, what I am supposed to use to get lat/long of an address TypeError:没有使用geokit-rails搜索将Symbol隐式转换为Integer - TypeError: no implicit conversion of Symbol into Integer for search with geokit-rails RoR:如何使用geokit-rails获取经纬度 - RoR: How to get lat and lng using geokit-rails ArgumentError: Unknown key: origin using geokit-rails - ArgumentError: Unknown key: origin using geokit-rails 使用Geokit-Rails按起点和终点位置搜索信息 - Searching Post by Origin & Destination locations using Geokit-Rails Rails&Geokit-配置:Geokit :: Geocoders :: GoogleGeocoder:Class的未定义方法api_key =(NoMethodError) - Rails & Geokit - config: Undefined method api_key= for Geokit::Geocoders::GoogleGeocoder:Class (NoMethodError)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM