无法找到有效的宝石安装activerecord-sqlite3-adapter。

9
我是一名 Ruby 的初学者。 我按照 http://rubyonrails.org/download 上的步骤安装了 Ruby on Rails,并通过观看 Youtube 视频教程创建了一个名为“Blog”的项目。http://www.youtube.com/watch?v=UQ8_VOGj5H8 但每当我使用命令rails s时,都会出现错误:
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/rubygems_integ
ration.rb:214:in `block in replace_gem': Please install the sqlite3 adapter: `ge
m install activerecord-sqlite3-adapter` (sqlite3 is not part of the bundle. Add
it to Gemfile.) (LoadError)

这种情况同时发生在我的笔记本电脑和台式电脑上,两者都使用Windows 7操作系统。 我尝试运行命令gem install activerecord-sqlite3-adapter,但是它给出了错误信息。

C:\Users\Ouye\blog>gem install activerecord-sqlite3-adapter
ERROR:  Could not find a valid gem 'activerecord-sqlite3-adapter' (>= 0) in any
repository
ERROR:  Possible alternatives: activerecord-jdbcsqlite3-adapter, activerecord-sq
lserver-adapter, activerecord-bq-adapter, activerecord-simpledb-adapter, activer
ecord-mysql2-adapter

我尝试了上面列出的所有替代方案,并更新了我的bundle,其中一些替代方案有效,而另一些则无效。在我尝试了上述所有替代方案并运行“rails s”之后,仍然会出现相同的错误提示,要求我安装sqlite3适配器。 以下是我的Gemfile内容:
source 'https://rubygems.org'

gem 'rails', '3.2.13'
gem 'sqlite3'

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

这是打包在宝石中的全部内容。
Gems included by the bundle:
  actionmailer (3.2.13)
  actionpack (3.2.13)
  activemodel (3.2.13)
  activerecord (3.2.13)
  activeresource (3.2.13)
  activesupport (3.2.13)
  arel (3.0.2)
  builder (3.0.4)
  bundler (1.3.5)
  coffee-rails (3.2.2)
  coffee-script (2.2.0)
  coffee-script-source (1.6.2)
  erubis (2.7.0)
  execjs (1.4.0)
  hike (1.2.2)
  i18n (0.6.1)
  journey (1.0.4)
  jquery-rails (2.2.1)
  json (1.7.7)
  mail (2.5.3)
  mime-types (1.23)
  multi_json (1.7.3)
  polyglot (0.3.3)
  rack (1.4.5)
  rack-cache (1.2)
  rack-ssl (1.3.3)
  rack-test (0.6.2)
  rails (3.2.13)
  railties (3.2.13)
  rake (10.0.4)
  rdoc (3.12.2)
  sass (3.2.9)
  sass-rails (3.2.6)
  sprockets (2.2.2)
  thor (0.18.1)
  tilt (1.4.1)
  treetop (1.4.12)
  tzinfo (0.3.37)

我会非常感激,如果有人能够解决我的问题。
3个回答

19

由于activerecord-sqlite3-adapter是已经包含在ActiveRecord中的适配器,所以您无法将其作为宝石安装。 问题不在于activerecord-sqlite3-adapter,而在于您的Gem捆绑包中没有sqlite3(错误消息在结尾告诉我们:“sqlite3不是捆绑包的一部分。”)

要解决此问题,请先将其添加到您的Gemfile:

# in your Gemfile
gem 'sqlite3'

接着从命令行运行:

$ bundle install

确保sqlite3正确安装并出现在您的Gem捆绑包中,一切应该正常运行。


2
我的 gem 文件中已经有了 'sqlite3'。当我运行命令 "bundle install" 时,它告诉我 "Your bundle is complete! Use bundle show [gemname] to see where a bundled gem is installed",但是 sqlite3 仍然没有出现在我的 Gem bundle 中。 - Ohhh
我同意他的最后一条评论。在我的gemfile中,我有平台:ruby do gem 'sqlite3' end,并安装了gem sqlite3。我能够从irb的readme示例中看到它工作,所以我知道那部分是有效的。这是一个旧版本的rails,当时sqlite3不是默认值。我会尝试使用最新版本的rails。他们在其中包含了一个示例应用程序,所以你应该没有问题运行它。祝好运。 - Douglas G. Allen

6

我曾经遇到了和你一样的问题,在经过多次尝试后,我找到了一些简单的步骤来修复它。

首先,在您的Gemfile中添加以下内容:

gem 'sqlite3', '1.3.5'

然后在控制台中运行:

bundle install

然后您应该按照正常流程继续操作


1
复制粘贴答案并不真正有帮助,除非你在对话中添加了新的内容。 - Arman H
1
这可能看起来像是复制粘贴,但上面的答案没有使用宝石版本,直到我添加了它才起作用。只是想分享我解决问题所做的确切步骤。 - Hans Gamarra De Lima

2

Ruby 2.0存在与sqlite3相关的问题,无法运行。如果你需要使用sqlite3,则必须降级到1.9.3版本。我没有这方面的文档链接,但我知道如果你降级到1.9.3版本,问题就会得到解决。我会尝试找到相关链接。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接