一旦我添加代码来访问我的.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
答案 0 :(得分:0)
SQLite
模块不存在,但名为SQLite3
(check the docs):
require 'sqlite3'
class Test2
def initialize()
@items = []
end
def total()
db = SQLite3::Database.open "Database.sqlite"
db.close()
return 0
end
end