按照本教程,我试图了解Sinatra ruby框架:
http://net.tutsplus.com/tutorials/ruby/singing-with-sinatra-the-recall-app-2/
然而,在运行gem安装并在test.rb中编写一个简单的sinatra服务器后如下:
require 'sinatra'
require 'datamapper'
get '/' do
"Hello, World!"
end
但是当我运行命令ruby test.rb
时,我收到以下错误:
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- datamapper (LoadError)
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from datamapper_test.rb:2:in `<main>'
glenn@ubuntu:~/Dropbox/Repositories/sandbox/sinatra$ ruby datamapper_test.rb
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- datamapper (LoadError)
from /usr/local/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from test.rb:3:in `<main>'
好像它无法找到datamapper gem。我该如何解决这个问题?
编辑:使用ruby 1.9.2
编辑(再次):gem list
的{parital}输出:
data_mapper (1.2.0)
data_objects (0.10.8)
datamapper (1.2.0)
devise (1.4.5)
directory_watcher (1.4.0)
dm-aggregates (1.2.0)
dm-constraints (1.2.0)
dm-core (1.2.0)
dm-do-adapter (1.2.0)
dm-migrations (1.2.0)
dm-serializer (1.2.1)
dm-sqlite-adapter (1.2.0)
d m-timestamps (1.2.0)
dm-transactions (1.2.0)
dm-types (1.2.1)
dm-validations (1.2.0)
do_sqlite3 (0.10.8)
sinatra (1.3.2, 1.2.6)
sqlite3 (1.3.5, 1.3.4)
sqlite3-ruby (1.3.3)
答案 0 :(得分:27)
您需要require 'data_mapper'
,而不是datamapper
。
请注意,有一个datamapper
gem和一个data_mapper
gem,但它们是相同的,只是名称不同。您需要在其中使用data_mapper
作为库名。
据我所知,datamapper
是data_mapper
的完整副本:
$ diff -r data_mapper-1.2.0/ datamapper-1.2.0/
diff -r data_mapper-1.2.0/Rakefile datamapper-1.2.0/Rakefile
21c21
< GEM_NAME = 'data_mapper'
---
> GEM_NAME = 'datamapper'
答案 1 :(得分:0)
gem install datamapper
可能有帮助:)
但是你还需要一个数据库和一个适配器,你会想要以某种方式使用gem。祝你好运,与dm + sinatra玩得开心!