3

我将首先给出我的规格:

  • RVM 1.12.1
  • 导轨 3.2.3
  • Ruby 1.9.3p125(2012-02-16 修订版 34643)[x86_64-darwin12.0.0]
  • RubyGem 1.8.21
  • OS X 10.8 山狮
  • Kenneth Reitz 的 OSX 10.7+ 的 GCC 安装程序,第 2 版(包括 X11 标头,错误修复)

我的 Gemfile 如下:

source 'https://rubygems.org'
gem 'rails', '3.2.3'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

    # See https://github.com/sstephenson/execjs#readme for more supported runtimes
    # gem 'therubyracer', :platform => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

我的 database.yml 是:

development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

当我启动服务器并转到默认主页并单击“查看环境”按钮时,我收到“ActiveRecord::ConnectionNotEstablished”错误。

当我检查控制台时,我看到:

/Users/username/.rvm/gems/ruby-1.9.3-p125@global/gems/bundler-1.1.3/lib/bundler/rubygems_integration.rb:147:in `block in replace_gem': Please install the mysql adapter: `gem install activerecord-mysql-adapter` (mysql is not part of the bundle. Add it to Gemfile.) (LoadError)
from /Users/username/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/activerecord-3.2.3/lib/active_record/connection_adapters/mysql_adapter.rb:5:in `<top (required)>'
from /Users/username/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
from /Users/username/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `block in require'
from /Users/username/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/username/.rvm/gems/ruby-1.9.3-p125@rails3tutorial2ndEd/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'

尽管我使用的是 SQLite 并且在任何地方都没有引用 MySQL。这可能是某种使用 10.8 的副作用吗?我难住了!

4

1 回答 1

0

几个月前,我正在使用 java 和 Play 开发一个项目!框架,我们使用一个名为 DATABASE_URL 的环境变量来轻松管理开发和生产中的数据库配置。在我的情况下,变量设置为mysql://root@localhost:3306/database_name.

事实证明,它也rails 3.2尝试从名为 DATABASE_URL 的环境变量中获取数据库配置。

这是 rails 3.2 分支上的代码:

https://github.com/rails/rails/blob/3-2-stable/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb#L91-135

rails 3.1 分支上的相同方法:

https://github.com/rails/rails/blob/3-1-stable/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb#L23-82

所以我只是删除了环境变量,一切又正常了。

于 2012-04-11T14:57:21.923 回答