【问题标题】:how to use Heroku's application database from another Heroku application如何从另一个 Heroku 应用程序使用 Heroku 的应用程序数据库
【发布时间】:2011-09-09 20:11:23
【问题描述】:

我目前在 Heroku 上运行了两个 Rails 3 应用程序。一个是主应用,另一个是主应用的论坛。

对于这两个应用程序,我想为用户使用单个数据库表。因此,在论坛应用程序中,我像这样覆盖了 ActiveRecord 数据库连接设置。

# User model in Forum application
class User < ActiveRecord::Base
  establish_connection(
    :adapter  => "postgres",
    :host     => "ec2-XXX-XXX-XXX-XXX-XXX.compute-X.amazonaws.com",
    :username => "username",
    :password => "password",
    :database => "db_name"
  )
end

通过覆盖配置,我得到 'activerecord-postgres-adapter' not found 异常。为了消除这个异常,我在 Gemfile 中添加了 'pg' gem。但我仍然面临同样的错误。

谁能告诉我,如何从另一个 Heroku 应用程序使用 Heroku 的应用程序数据库。还有我需要使用哪个 gem 来避免上述异常。

谢谢你..

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 postgresql heroku


    【解决方案1】:

    使用 ActiveResource 代替 ActiveRecord。

    【讨论】:

    • Jeremy,谢谢您的回复。我通过使用适配器“postgresql”而不是“postgres”建立连接(:adapter =>“postgresql”,:host =>“ec2-XXX -XXX-XXX-XXX-XXX.compute-X.amazonaws.com", :username => "username", :password => "password", :database => "db_name" )
    猜你喜欢
    • 2015-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-14
    • 2011-04-20
    • 1970-01-01
    • 2016-05-29
    相关资源
    最近更新 更多