如何使用build_connection-RUBY

我对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)

emheiyan 回答:如何使用build_connection-RUBY

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2871171.html

大家都在问