未初始化的常量SQLite错误

时间:2012-08-23 09:27:05

标签: ruby sqlite nameerror

一旦我添加代码来访问我的.sqlite数据库,我就会收到一个奇怪的错误:

in 'total': uninitialized constant Test2::SQLite (NameError)

我的代码如下:

Test1.rb

require_relative 'Test2.rb'

co = Test2.new()
price = co.total

Test2.rb

require 'sqlite3'

class Test2

    def initialize()
            @items = []
    end

    def total()
        db = SQLite::Database.open "Database.sqlite"
        db.close()
        return 0
    end
end

1 个答案:

答案 0 :(得分:0)

SQLite模块不存在,但名为SQLite3check the docs):

require 'sqlite3'

class Test2

    def initialize()
            @items = []
    end

    def total()
        db = SQLite3::Database.open "Database.sqlite"
        db.close()
        return 0
    end
end