为什么Rails找不到宝石?

问题描述 投票:0回答:1

我在我的gemfile中安装了geocoder gem,如下所示:

gem 'geocoder', '~> 1.5.1'

然后我将这一行添加到我的模型中

class Place < ApplicationRecord 
  geocoded_by :address
end

我收到此错误:

undefined method `geocoded_by' for #<Class:0x00007f8b58b763b8>

知道我为什么会收到这个错误吗?我认为安装gem就足够了,但显然,Rails无法找到Geocoder库。

更新#1这是我的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]

更新#2当我运行gem list geocoder时,这是输出:

*** LOCAL GEMS ***

geocoder (default: 1.5.1, 1.4.8, 1.4.7)

更新#3我不认为它只是地理编码器......

我把它添加到我的gemfile中:

group :development do
  # other gems are here, they're just not listed.
  gem "better_errors"
  gem "binding_of_caller"
end

但是,我仍然会遇到常规错误。所以现在,甚至没有找到更好的宝石错误!!!

更新#4添加我的场所模型和应用程序记录

class Place < ApplicationRecord
  extend FriendlyId
  friendly_id :name, use: :slugged
  geocoded_by :address
end

class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true
end

更新#5 Github发布推荐信

建议在模型文件的顶部添加:

extend Geocoder::Model::ActiveRecord

这是一种解决方案,但即使这样也行不通!

我收到这个错误:uninitialized constant Place::Geocoder

更新#6 |临时修复

我将gem 'geocoder', '~> 1.5.1'降级为gem 'geocoder', '1.5'

有任何想法吗?

ruby-on-rails ruby rails-geocoder
1个回答
0
投票

我认为问题是必须做bundle update。总是你在Gemfile中添加gem是必要的。

© www.soinside.com 2019 - 2024. All rights reserved.