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

undefined method `within' #99

Closed alain-andre closed 8 years ago

alain-andre commented 8 years ago

I'm trying to add geokit-rails to my project. I want to be abble to find the route that contains the closest step to a location.

My models are so :

    class Route < ActiveRecord::Base
      has_many :steps

      acts_as_mappable :default_units => :kms
    end

    class Step < ActiveRecord::Base
      belongs_to :route

      acts_as_mappable :through => :route
    end

My Step's schema :

    create_table "steps", force: :cascade do |t|
        t.float    "lat"
        t.float    "lng"
        t.text     "formatted_address"
        t.string   "vicinity"
        t.string   "name"
        t.integer  "distance"
        t.integer  "duration"
        t.integer  "route_id"
        t.datetime "created_at",         null: false
        t.datetime "updated_at",         null: false
      end

My Gemfile use gem 'geokit-rails', :git => 'https://github.com/geokit/geokit-rails' because if I use only gem 'geokit-rails' I have an error Could not find generator 'geokit_rails:install' when trying to generate config.

My geokit_config.rb :

Geokit::default_units = :kms # others :kms, :nms, :meters
Geokit::default_formula = :flat
Geokit::Geocoders::request_timeout = 3

Now my test try the following

    test "Je dois pouvoir trouver un trajet près de coordonnées gps via ses étapes" do
        route = routes(:default)

        route.within(10, :origin => [1.23456,-5.3269])
      end

And I get this error NoMethodError: undefined method 'within' for #<Route:0xa1e9d88> how is it possible ?

alain-andre commented 8 years ago

Well, I'm not using the ActiveRecord class but an instance of...my bad.