我需要观察一个远程数据库表。我正在查看如下代码:
class RemotetableObserver < ActiveRecord::Observer
# Need to watch the remote table
ActiveRecord::Base.establish_connection "remoteDB"
observe :remotetable
def after_create(row)
doStuff.create(row)
end
end
我已经添加了
config.active_record.observers = :remotetable_observer
到我的 application.rb 配置文件,我的 database.yml 连接到远程数据库。
我得到了,NameError: uninitialized constant remotetable
所以我创建了一个进一步的模型:
# remotetable.rb
class Remotetable < ActiveRecord::Base
# establish_connection(ActiveRecord::Base.configurations["otherdb_#{RAILS_ENV}"])
ActiveRecord::Base.establish_connection "remoteDB"
self.table_name = "remotetable"
end
但仍然得到同样的错误:NameError: uninitialized constant remotetable
请问有什么想法吗?