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. 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. 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.
merge_conditions is a deprecated ActiveRecord::Base method from rails 2.3.8.
inserted into app/vendor/plugins/geokit-rails/lib/geokit-rails/acts_as_mappable.rb
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…
I guess I’ll find out if the original code calls merge_conditions anywhere else tho. 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…