Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jan opened this issue Nov 22, 2010 · 4 comments
Closed

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

jan opened this issue Nov 22, 2010 · 4 comments

Comments

@jan
Copy link

jan commented Nov 22, 2010

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
Copy link

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
Copy link

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
Copy link

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)

mnoack added a commit that referenced this issue Jun 19, 2013
allow versions of Rails above 3.0.x
@ryankopf
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants