我对Ruby语言不太了解。我正在尝试创建一个类来建立oracle数据库连接。该类将接收要在其他类中重用的连接。我正在从事一个自动化项目,需要建立此连接以便为自动化测试准备大量数据。下面,我将提供我的代码,以便有人可以指导我如何创建此类。在这种情况下,将无法访问连接类。
require "rubygems"
require "active_record"
class Connection
attr_accessor :connection
ActiveRecord::Base.establish_connection(
:adapter => "oracle_enhanced",
:database => "dboraclehomolog.com.br:1521/homolog",
:username => "USER",
:password => "password",
)
def initialize
connection = ActiveRecord::Base.connection
end
def execute_select(sql)
results = ActiveRecord::Base.connection.execute(sql)
if results.nil?
return results
else
return false
end
end
def exec(sql)
begin
ActiveRecord::Base.connection.execute(sql)
rescue => e
puts e.message
end
end
end
错误:未初始化的常量Repactuar :: Conexao(NameError)