<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d4684235500622716427\x26blogName\x3dCaiwangqin\x27s+blog\x26publishMode\x3dPUBLISH_MODE_HOSTED\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://blog.caiwangqin.com/search\x26blogLocale\x3dzh_CN\x26v\x3d2\x26homepageUrl\x3dhttp://blog.caiwangqin.com/\x26vt\x3d3393395200455623441', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Caiwangqin's blog

Focus on Cloud Service, Smart Hardware, Architecture, Technic and beyond…

Ruby on Raisl Multi Database Connect

2006年12月14日星期四

今天看到 Rails可以有两个以上的数据库吗 以及 Multiple database handling with Rails。他們的作法有點詭異,而且有一個關鍵性的問題,每次 request 每個不相關的頁面也都得連接一次 external database。可是 Rails 要做這件事情應該沒那麼複雜呀?


1. 設定 config



extradb_production:

adapter:     mysql

host:        localhos

username:    root

password:    blabla

database:    extradb_prod


2. 在相關 Model 利用 estabilish_connection 去做連接而外設定


class lala < ActiveRecord::Base
establish_connection :extradb_production
end


然後收工,連跨 DB 的關連性都沒問題。


Link to 一次連接 Multi Database


标签:

posted by Jesse Cai, 上午7:50

0 Comments:

发表评论

订阅 帖子评论 [Atom]

<< 主页