我是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)
然后由于这些错误而导致许多其他问题。 我尝试重新安装许多宝石,但似乎没有任何效果。
编辑:完整的错误代码是:
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>'
答案 0 :(得分:7)
我有这个问题,在Windows上使用ruby 1.9.3 - 通过从http://www.sqlite.org/download.html下载sqlite3.dll并将其放入C:\ Ruby193 \ bin
来修复它答案 1 :(得分:2)
尝试添加:
require 'dm-sqlite-adapter'
如果这不能解决问题,您也可以尝试更改
DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/recall.db")
到
DataMapper.setup(:default, 'sqlite:recall.db')
并查看是否修复了它。我真的不知道原因,但做上面的(单引号,没有“3”,没有路径)修复了我在尝试特定设置时收到的错误。