[英]Dynamic Subclassing and ActiveRecord establish_connection with PostgreSQL database
I'm trying to create a utility to copy a subset of records from a single table of one PostgreSQL database to that same table in another PostgreSQL database. 我正在尝试创建一个实用程序,将记录的子集从一个PostgreSQL数据库的单个表复制到另一个PostgreSQL数据库的同一表。 I'm doing this with dynamic subclassing, but it's not working: it raises the error "xxx database is not configured" (where xxx is my database URL, something like "postgres://username:password@computername:5432/databasename". I know the URL is good because I copied it from my Heroku configuration and I am able to access the database from pgAdmin3 on my local machine. Here's the code: 我正在使用动态子类进行此操作,但无法正常工作:它引发错误“未配置xxx数据库”(其中xxx是我的数据库URL,类似“ postgres:// username:password @ computername:5432 / databasename”)我知道URL是好的,因为我是从Heroku配置中复制的,并且能够从本地计算机上的pgAdmin3访问数据库。
puts "Enter the database URL"
url = gets.chomp
db_conn = Class.new(ActiveRecord::Base) do
establish_connection url
end
Support for establish_connection(url) was added in Rails 3.2; 在Rails 3.2中添加了对created_connection(url)的支持; I was running Rails 3.1.3. 我正在运行Rails 3.1.3。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.