Rails 二个 rails 项目共用一个数据库

fayake · 2014年02月17日 · 最后由 search 回复于 2014年02月17日 · 2089 次阅读

怎么让二个 rails 项目共用一个数据库 只做取数据和写数据 是 mysql 数据库

两个项目的database.yml都是同样的内容不可以么?

那我在控制台

User.first

不能调用到数据库的信息 这个要怎么配置

哦。。。不仅需要同样的数据库还需要同样的 model 啊,那我就真不太清楚了。而且每个 model 都要有相同的方法比如验证、scope 等那确实是有些麻烦

remote_database:
  adapter: mysql2
  encoding: utf8
  host: xxx.xxx.xxx.xxx
  pool: 5
  username: "xxx"
  password: "xxx"
  database: xxx
class User < ActiveRecord::Base
  establish_connection "remote_database"
end

Git Submodule 🆙

需要 登录 后方可回复, 如果你还没有账号请 注册新账号