首先要做的事情是:我使用的是Ruby 1.9.3和DataMapper 1.2.0。
我创建了以下看似简单的模型:
class User
include DataMapper::Resource
property :id, Serial
property :username, String
property :password, BCryptHash
property :name, String
property :email, String
property :created_at, DateTime
end
我可以在一个irb shell中启动它,它会创建一个数据库,每个人都很开心。但后来我尝试了:
tim = User.new(:username => "tim", :password => "password", :name => "Tim", :email => "my@email.com", :created_at => Time.now)
我收到一个用户实例,可以打印到控制台并且所有属性都完好无损。我可以运行tim.save!
并看到成功。但是,如果我在此时尝试列出用户,我会遇到错误:
irb(main):001:0> User.all
(Object doesn't support #inspect)
=>
irb(main):002:0> User.first
NoMethodError: undefined method `new!' for DateTime:Class
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:153:in `next!'
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:153:in `block in read'
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:276:in `with_connection'
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:141:in `read'
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/repository.rb:162:in `read'
from /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/model.rb:377:in `first'
from (irb):5
from /usr/local/Cellar/ruby/1.9.3-p0/bin/irb:12:in `<main>''
任何线索?由于不支持#inspect
,所以没有其他任何东西真的出现在SO或Google上,而且Ruby stdlib文档明显缺少DateTime的new!
方法。
答案 0 :(得分:2)
想出这个 - 它与我使用的do_sqlite3
gem的版本有关,因为我切换到Ruby 1.9.3后没有重新安装。如this bug中所述,我需要重新安装所有do_*
宝石,才能在它工作之前重新链接1.9.3。