Ruby on rails 3 Rails 3中带有Desive的远程登录数据库

Ruby on rails 3 Rails 3中带有Desive的远程登录数据库,ruby-on-rails-3,devise,Ruby On Rails 3,Devise,我正在构建一个应用程序,将用户数据保存在一个单独的(远程)数据库中。如何使Deave使用该数据库而不是默认数据库?为远程数据库添加一个条目到database.yml,然后在用户(或称为Deave模型)中告诉它使用远程条目。差不多吧 database.yml remote_development: host: replace_with_ip_address_of_remote_db #[all the other usual db settings like adapter, userna

我正在构建一个应用程序,将用户数据保存在一个单独的(远程)数据库中。如何使Deave使用该数据库而不是默认数据库?

为远程数据库添加一个条目到database.yml,然后在用户(或称为Deave模型)中告诉它使用远程条目。差不多吧

database.yml

remote_development:
  host: replace_with_ip_address_of_remote_db
  #[all the other usual db settings like adapter, username, db name, etc.]

#[don't forget remote_test and remote_production entries]
User.rb

establish_connection "remote_#{RAILS_ENV}"

您可能还希望在模型级别添加一些缓存,以减少远程数据库的往返。

为远程数据库向database.yml添加一个条目,然后在您的用户(或您的设计模型)中告诉它使用远程条目。差不多吧

database.yml

remote_development:
  host: replace_with_ip_address_of_remote_db
  #[all the other usual db settings like adapter, username, db name, etc.]

#[don't forget remote_test and remote_production entries]
User.rb

establish_connection "remote_#{RAILS_ENV}"
您可能还希望在模型级别添加一些缓存,以减少远程数据库往返