geokit / geokit-rails

Official Geokit plugin for Rails/ActiveRecord. Provides location-based goodness for your Rails app. Requires the Geokit gem.
MIT License
1.57k stars 245 forks source link

Rails 3: ArgumentError (Unknown key(s): within, origin) / fix #24

Closed jan closed 3 years ago

jan commented 13 years ago

I just started migrating my app to Rails 3 and for my old find syntax, Court.all(:conditions => ["auctions_count > 0 AND id <> ?", @court.id], :origin => [@court.lat, @court.lng], :within => 150.0, :order => "auctions_count DESC", :limit => 5) I get the following error, and provide an easy (and nasty) fix for it below.

ArgumentError (Unknown key(s): within, origin):
  activesupport (3.0.1) lib/active_support/core_ext/hash/keys.rb:43:in `assert_valid_keys'
  activerecord (3.0.1) lib/active_record/relation/spawn_methods.rb:89:in `apply_finder_options'
  activerecord (3.0.1) lib/active_record/relation/finder_methods.rb:143:in `all'
  activerecord (3.0.1) lib/active_record/base.rb:439:in `__send__'
  activerecord (3.0.1) lib/active_record/base.rb:439:in `all'
  (my controller)

It works when I monkey patch the following with an initializer. module ActiveRecord module SpawnMethods VALID_FIND_OPTIONS = [ :conditions, :include, :joins, :limit, :offset, :extend, :order, :select, :readonly, :group, :having, :from, :lock, :origin, :within ] end end

This works for me with

ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9]

rails 3.0.1

geokit gem 1.5.0

geokit_rails plugin 1.?.? (says 1.1.4 in about.yml and 1.2.0 in CHANGELOG.rdoc, checked out November 21, 2010)

wwvuillemot commented 13 years ago

This worked for me, too. Very clunky. I thought ensuring I was on 3.0.7 rails/activerecord might help; it does not. For now I have this kludge in my application.rb

mhenrixon commented 13 years ago

Have the same problem and I have no idea how to fix it. The suggested monkey patch doesn't work for me and I have no idea where to start looking. Any time I try a count + group by I get unkown key(s)

eliotsykes commented 11 years ago

I had a similar problem using the acts_as_geocodable plugin.

You can avoid duplicating the existing find options with this fix:

# Put in config/initializers/geo_find_options.rb
ActiveRecord::SpawnMethods::VALID_FIND_OPTIONS.push(:within, :origin, :beyond, :units)
ryankopf commented 3 years ago

I am closing all issues that are more than 6 years old now, as the gem has had significant updates and is likely people with these old issues are no longer having the issues. If you are currently still experiencing this issue or need help feel free to submit a new issue, thank you.