【发布时间】:2016-12-23 13:57:23
【问题描述】:
无法通过我在 Windows 10 上的 Sinatra 应用程序中的活动记录连接到数据库,在 OSX 上没有问题,但我仍然希望能够从我的 Windows 机器上进行开发。
完全错误: C:/Ruby23-x64/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:120:in `require': 无法加载 'active_record/connection_adapters/postgresql_adapter'。确保 config/database.yml 中的适配器有效。如果您使用“mysql2”、“postgresql”或“sqlite3”以外的适配器,请将必要的适配器 gem 添加到 Gemfile。 (加载错误)
Ruby 版本:2.3.1
gem 'pg'
^^ 包含在 Gemfile 中
require 'sinatra/activerecord'
^^ 在 app.rb 中
不相关:Could not load 'active_record/connection_adapters/postgresql_adapter'
环境.rb:
configure :development do
ActiveRecord::Base.establish_connection(
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
:host => 'localhost',
:username => 'postgres',
:password => '******',
:database => '******',
:port => 5432
:encoding => 'utf8'
)
end
数据库.yml: 发展: 适配器:postgresql 编码:unicode 数据库:与environments.rb相同 游泳池:5 用户名:与environments.rb相同 密码:与environments.rb相同
【问题讨论】:
标签: ruby postgresql activerecord sinatra sinatra-activerecord