5

我是 Sinatra 的新手,我正在尝试使用 SQLite3 和 Datamapper 创建一个数据库。我安装了 gems 和适配器,然后尝试在文件中执行此代码:

#config
require 'sinatra'
require 'sinatra/contrib' if development?
require 'data_mapper'

DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/recall.db")  
DataMapper.finalize.auto_upgrade!  

当我执行文件时,命令行给了我这个错误:

C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require':126: The specified module could not be found.   - 
C:/Ruby193/lib/ruby/gems/1.9.1/gems/do_sqlite3-0.10.10-x86-mingw32/lib/do_sqlite3/1.9/do_sqlite3.so (LoadError)

然后由于这些错误而出现了许多其他问题。我尝试重新安装许多 gem,但似乎没有任何效果。

编辑:完整的错误代码是这样的:

C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require':126: The specified module could not be found.   - C:/Ruby193/lib/ruby/gems/1.9.1/gems/do_sqlite3-0.10.10-x86-mingw32/lib/do_sqlite3/1.9/do_sqlite3.so (LoadError)
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/backports-2.6.5/lib/backports/tools.rb:314:in `require_with_backports'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/do_sqlite3-0.10.10-x86-mingw32/lib/do_sqlite3.rb:31:in `rescue in <top (required)>'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/do_sqlite3-0.10.10-x86-mingw32/lib/do_sqlite3.rb:26:in `<top (required)>'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/backports-2.6.5/lib/backports/tools.rb:314:in `require_with_backports'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/dm-sqlite-adapter-1.2.0/lib/dm-sqlite-adapter/adapter.rb:1:in `<top (required)>'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/backports-2.6.5/lib/backports/tools.rb:314:in `require_with_backports'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/dm-sqlite-adapter-1.2.0/lib/dm-sqlite-adapter.rb:1:in `<top (required)>'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/backports-2.6.5/lib/backports/tools.rb:314:in `require_with_backports'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/adapters.rb:163:in `load_adapter'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/adapters.rb:133:in `adapter_class'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/adapters.rb:13:in `new'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core.rb:230:in `setup'
from test.rb:7:in `<main>'
4

2 回答 2

7

我遇到了这个问题,在 Windows 上使用 ruby​​ 1.9.3 - 通过从http://www.sqlite.org/download.html下载 sqlite3.dll并将其放入 C:\Ruby193\bin来修复它

于 2013-07-26T11:55:06.947 回答
2

尝试添加:

require 'dm-sqlite-adapter'

如果这不能解决问题,您也可以尝试更改

DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/recall.db")

DataMapper.setup(:default, 'sqlite:recall.db')

看看是否可以解决它。我真的不知道原因,但是执行上述操作(单引号,没有“3”,没有路径)修复了我在尝试特定设置时收到的错误。

于 2012-12-31T01:49:24.607 回答