在Ruby on Rails中动态连接到第二个MySQL数据库 [英] Dynamic connection to second MySQL database in Ruby on Rails

查看:115
本文介绍了在Ruby on Rails中动态连接到第二个MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails应用程序,该应用程序将迁移用户内容.我需要通过表单来获取数据库参数,并使用它们来连接到给定的数据库.实现此目标的最佳方法是什么?我尝试不高兴使用Mysql.real_connect.

I'm working on a rails application that will migrate user content. I need to take in database parameters via a form and use them to connect to the given database. What's the best way to achieve this? I've attempted using Mysql.real_connect with no joy.

推荐答案

您可以调用 establish_connection 和新参数,然后使用

You can call establish_connection with your new parameters and then use connection normally.

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

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