gpt4 book ai didi

ruby-on-rails - 新的 OS X Ruby on Rails 安装无法连接到数据库

转载 作者:行者123 更新时间:2023-12-03 17:35:26 25 4
gpt4 key购买 nike

我先给出我的规范:

  • RVM 1.12.1
  • rails 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 header 、错误修复)

我的 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 的副作用吗?我很难过!

最佳答案

几个月前,我在做一个使用 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

所以我只是把环境变量去掉,一切又恢复正常了。

关于ruby-on-rails - 新的 OS X Ruby on Rails 安装无法连接到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10082205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com