使用rails连接外部数据库时出错

问题描述 投票:0回答:1

伙计们,我正在尝试将我的应用程序连接到外部数据库来使用它。

我在文件末尾的database.yml中添加了配置。

external_db:
  adapter: postgresql
  encoding: utf8
  database: db_name
  host: https://hostdb.com.br/
  username: user
  password: pass
  port: 5734

我为它创建了一个模型。

class ExternalDb < ApplicationRecord
  self.abstract_class = true
  establish_connection :external_db
end

好吧..在此之后我尝试与

进行简单的咨询

x = ExternalDb.connection.execute("select * from PRODUTOS;")

我收到以下错误:

/home/rails/deploy/shared/vendor/bundle/ruby/3.0.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql_adapter.rb:87:in `rescue in new_client': could not translate host name "https://hostdb.com.br/" to address: Name or service not known (ActiveRecord::ConnectionNotEstablished)
/home/rails/deploy/shared/vendor/bundle/ruby/3.0.0/gems/pg-1.5.4/lib/pg/connection.rb:819:in `connect_start': could not translate host name "https://hostdb.com.br/" to address: Name or service not known (PG::ConnectionBad)
ruby-on-rails ruby postgresql
1个回答
0
投票

hostdb.com.br
“主机”,服务器本身的名称。

https://hostdb.com.br/
是一个 URL,专门使用 https 协议连接到
hostdb.com.br
上的 Web 服务器。

© www.soinside.com 2019 - 2024. All rights reserved.