Reputation: 1577
I installed the geocoder gem in my gemfile like this:
gem 'geocoder', '~> 1.5.1'
Then I added this line to my model
class Place < ApplicationRecord
geocoded_by :address
end
I get this error:
undefined method `geocoded_by' for #<Class:0x00007f8b58b763b8>
Any idea why I'm getting this error? I figured installing the gem would be enough, but apparently, Rails can't locate the Geocoder library.
UPDATE #1 Here is my gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1'
gem 'rails', '~> 5.2.2'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 3.11'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'mini_racer', platforms: :ruby
gem 'coffee-rails', '~> 4.2'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'bootsnap', '>= 1.1.0', require: false
gem 'impressionist', '~> 1.5', '>= 1.5.1'
gem 'geocoder', '~> 1.5', '>= 1.5.1'
group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
gem 'capybara', '>= 2.15'
gem 'rspec-rails'
gem 'selenium-webdriver'
gem 'chromedriver-helper'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
UPDATE #2
When I run gem list geocoder
, This is what outputs:
*** LOCAL GEMS ***
geocoder (default: 1.5.1, 1.4.8, 1.4.7)
UPDATE #3 I don't think it's just geocoder...
I added this to my gemfile:
group :development do
# other gems are here, they're just not listed.
gem "better_errors"
gem "binding_of_caller"
end
However, I'm still getting regular errors. So now, not even the better gems error is being found!!!
UPDATE #4 Adding my Place Model and application record
class Place < ApplicationRecord
extend FriendlyId
friendly_id :name, use: :slugged
geocoded_by :address
end
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
UPDATE #5 Github issues recommendation
It was recommended to add this at the top of my model file:
extend Geocoder::Model::ActiveRecord
This was sort of a work-around solution, but not even this worked!
I get this error: uninitialized constant Place::Geocoder
UPDATE #6 | Temporary Fix
I downgraded gem 'geocoder', '~> 1.5.1'
to gem 'geocoder', '1.5'
Any ideas?
Upvotes: 0
Views: 166
Reputation: 1
I think that the problem is that necessary to do
bundle update
.Always that you add gem in your Gemfile is necessary to do this.
Upvotes: 0