【问题标题】:Could not load 'active_record/connection_adapters/postgresql_adapter' Sinatra - Windows 10无法加载“active_record/connection_adapter/postgresql_adapter”Sinatra - Windows 10
【发布时间】: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


    【解决方案1】:

    您在 enviroments.rb 中的适配器应该是 postgresql。没有别的了。

    【讨论】:

      【解决方案2】:

      我不知道究竟是为什么,但是 Ruby 2.3.1 版在 Windows 上与 Sinatra 配合得不好。我降级到 Ruby 2.2.5 并保持 activeRecord '5.0.0' 并且一切正常。

      【讨论】:

      • 刚刚设置了RubyMine,试图让sinatra/postgres 在Windows 10 2.3.1 上工作,发现同样的错误。
      猜你喜欢
      • 1970-01-01
      • 2013-08-19
      • 1970-01-01
      • 2016-12-14
      • 1970-01-01
      • 2014-11-17
      • 2020-07-04
      • 2013-08-11
      • 2018-04-17
      相关资源
      最近更新 更多