【发布时间】:2019-05-01 02:51:47
【问题描述】:
我有一个 rails 5 应用,需要报告功能。我现在想将它保留在应用程序中,而不是使用 rails 引擎。报告功能连接到 Heroku 关注者数据库。
我可以复制我的普通模型并将它们用作连接到关注者数据库的父类的子类,如下所示?
module Reporting
class Base < ActiveRecord::Base
self.abstract_class = true
establish_connection("follower_database")
end
end
module Reporting
class User < Reporting::Base
# I would like to avoid copying and pasting all the user model code here and have some fancy way for it to just inherit or included it all so when we add new associations etc. the reporting classes automatically get it..
end
end
【问题讨论】:
-
establish_connection是 ActiveRecord::Base 的方法。不管你是否使用 Rails,都应该使用 ActiveRecord::Base。
标签: ruby-on-rails ruby heroku ruby-on-rails-5 rails-activerecord