当我运行一个新的空 rails (4.0) 站点时出现此错误:
Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile.
我有一个用 devkit 构建的有效 sqlite3 gem。我为此做了一个愚蠢的测试:
w:...> ruby hello.rb
hello world
test.db is done.
它还创建了一个空数据库,名为“test.db”,如下所示。简单的红宝石脚本:
require "sqlite3"
puts "hello world"
# Open a database
db = SQLite3::Database.new "test.db"
puts "test.db is done."
我的结论是sqlite3 gem 工作正常,并且在某个地方的 rails 内部有些问题。欢迎提出建议或解释。
在关于Gemfile的评论之后的一点更新:
# Use sqlite3 as the database for Active Record
gem 'sqlite3', group: [:development, :test]
另外,我使用了bundle show命令,我觉得这很奇怪:
w:...> bundle show sqlite3
Could not find gem 'sqlite3'.
Did you mean sqlite3?
当我进行捆绑安装时,输出列表不包括 sqlite3。我应该添加 Gemfile,其他所有内容都是由“ rails new train ”命令(项目名称,当然是“ train ”)直接生成的。
环境是在 Windows 7 64 位 PC 上安装 Ruby v2、Rails v4。我有 PIK 来管理不同版本的 ruby。欢迎提出建议,在此先感谢,威尔。
一切都是/应该是全新的 Rails 4/Ruby 2 配置。我也在添加服务器的堆栈转储,因为理论上全新安装应该可以工作。
Gem::LoadError (Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile.):
activerecord (4.0.0) lib/active_record/connection_adapters/connection_specification.rb:58:in `rescue in resolve_hash_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/connection_specification.rb:55:in `resolve_hash_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/connection_specification.rb:46:in `resolve_string_connection'
activerecord (4.0.0) lib/active_record/connection_adapters/connection_specification.rb:30:in `spec'
activerecord (4.0.0) lib/active_record/connection_handling.rb:39:in `establish_connection'
activerecord (4.0.0) lib/active_record/railtie.rb:175:in `block (2 levels) in <class:Railtie>'
activesupport (4.0.0) lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
activesupport (4.0.0) lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
activesupport (4.0.0) lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
activesupport (4.0.0) lib/active_support/lazy_load_hooks.rb:44:in `each'
activesupport (4.0.0) lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
activerecord (4.0.0) lib/active_record/base.rb:322:in `<module:ActiveRecord>'
activerecord (4.0.0) lib/active_record/base.rb:22:in `<top (required)>'
activerecord (4.0.0) lib/active_record/query_cache.rb:50:in `restore_query_cache_settings'
activerecord (4.0.0) lib/active_record/query_cache.rb:43:in `rescue in call'
activerecord (4.0.0) lib/active_record/query_cache.rb:32:in `call'
activerecord (4.0.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.0) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.0) lib/active_support/callbacks.rb:373:in `_run__398267657__call__callbacks'
activesupport (4.0.0) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `block in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.0) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:in `call'
railties (4.0.0) lib/rails/engine.rb:511:in `call'
railties (4.0.0) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
B:/lang/ruby/v02.00/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
B:/lang/ruby/v02.00/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
B:/lang/ruby/v02.00/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'