我想重命名一个表...(任何表.)
我试过这行代码:
ActiveRecord::ConnectionAdapters::SchemaStatements.rename_table(old_name, new_name)
Run Code Online (Sandbox Code Playgroud)
这是奇怪的事情.我知道我第一次使用它,但现在我得到了这个错误:ActiveRecord :: ConnectionAdapters :: SchemaStatements:模块的未定义方法`rename_table'
有什么我需要设置的吗?
我正在使用rails 2.3.5和mysql.
我有一个型号TableA和另一个型号TableB.TableA完全正常..但我需要为TableB交换连接.我正在连接到其他地方的其他服务器,所以我必须检查该表是否存在.如果没有,我将创建一个新表.
TableB.establish_connection(new_database_params)
unless TableB.table_exists?
ActiveRecord::Base.establish_connection(new_database_params)
ActiveRecord::Schema.define do
create_table :table_bs do |t|
t.column :text, :string
end
end
ActiveRecord::Base.establish_connection("#{RAILS_ENV}")
end
Run Code Online (Sandbox Code Playgroud)
我注意到TableB.establish_connection(new_database_params)将我连接到新服务器.那完全没问题.
当我尝试创建一个新表时,我仍然需要调用ActiveRecord :: Base来交换连接.有没有办法在ActiveRecord :: Schema上交换连接?(类似于Model.establish_connection?)
当我将日志记录参数设置为Daemons(1.1.0)gem时,我将如何实现与此行相似的行为?
logger = Logger.new('foo.log', 10, 1024000)
Run Code Online (Sandbox Code Playgroud)
守护进程选项:
options = {
:ARGV => ['start'],
:dir_mode => :normal,
:dir => log_dir,
:multiple => false,
:ontop => false
:mode => :exec,
:backtrace => true,
:log_output => true
}
Run Code Online (Sandbox Code Playgroud)