Rails中多个数据库 [英] Multiple databases in Rails

查看:148
本文介绍了Rails中多个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以这样做?在一个单一的应用程序,用于管理许多项目的SQLite。 我要的是有一个不同的数据库,为每个项目我的应用程序的管理..相同结构的数据库这么多份,但在他们不同的数据。我会选择它复制到的URI PARAMS使用基地。

Can this be done? In a single application, that manages many projects with SQLite. What I want is to have a different database for each project my app is managing.. so multiple copies of an identically structured database, but with different data in them. I'll be choosing which copy to use base on params on the URI.

这是针对1.安全性做了..我在这种编程的newbe,我不希望它发生,由于某种原因而工作的一个项目一个又一个被损坏。2.方便易用的备份老项目归档

This is done for 1. security.. I'm a newbe in this kind of programming and I don't want it to happen that for some reason while working on a Project another one gets corrupted.. 2. easy backup and archive of old projects

推荐答案

Rails的默认情况下是不适合多数据库体系结构,在大多数情况下,它没有任何意义可言。 但是,是的,你可以使用不同的数据库和连接。

Rails by default is not designed for a multi-database architecture and, in most cases, it doesn't make sense at all. But yes, you can use different databases and connections.

下面是一些参考:

  • ActiveRecord的:连接到多个数据库在不同型号
  • <一个href="http://robbyonrails.com/articles/2007/10/05/multiple-database-connections-in-ruby-on-rails">Multiple on Rails的
  • 在Ruby的数据库连接
  • <一个href="http://drnicwilliams.com/2007/04/12/magic-multi-connections-a-facility-in-rails-to-talk-to-more-than-one-database-at-a-time/">Magic多连接
  • ActiveRecord: Connection to multiple databases in different models
  • Multiple Database Connections in Ruby on Rails
  • Magic Multi-Connections

这篇关于Rails中多个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆