这是我的代码:
require 'date'
FactoryGirl.define do
factory :construction_site do
startdate = Date.today - rand(500)
enddate = startdate + (1 + rand(1000))
name { Faker::Lorem.words(2) }
address {Faker::Address.street_address + "\n" + Faker::Address.zip_code + " " + Faker::Address.city}
internalnumber { "CON" + ( 1 + rand(50000)) }
self.begin { startdate }
self.end { enddate }
finished { enddate < Date.today }
user
customer
end
end
我得到这个错误:
/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/core_ext/
date/calculations.rb:100:in `-': expected numeric (TypeError)
from /Users/kannix/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_supp
ort/core_ext/date/calculations.rb:100:in `minus_with_duration'
from /Users/kannix/railsapp/spec/factories/construction_sites.rb:5
:in `block (2 levels) in <top (required)>'
from /Users/kannix/.rvm/gems/ruby-1.9.3-p125/gems/factory_girl-4.1.0/lib/factory_girl
/syntax/default.rb:18:in `instance_eval'
from /Users/kannix/.rvm/gems/ruby-1.9.3-p125/gems/factory_girl-4.1.0/lib/factory_girl
/syntax/default.rb:18:in `factory'
from /Users/kannix/railsapp/spec/factories/construction_sites.rb:4
:in `block in <top (required)>'
from /Users/kannix/.rvm/gems/ruby-1.9.3-p125/gems/factory_girl-4.1.0/lib/factory_girl
/syntax/default.rb:49:in `instance_eval'
from /Users/kannix/.rvm/gems/ruby-1.9.3-p125/gems/factory_girl-4.1.0/lib/factory_girl
/syntax/default.rb:49:in `run'
from /Users/kannix/.rvm/gems/ruby-1.9.3-p125/gems/factory_girl-4.1.0/lib/factory_girl
/syntax/default.rb:7:in `define'
from /Users/kannix/railsapp/spec/factories/construction_sites.rb:3
:in `<top (required)>'
我的错误在哪里,该代码中是否还有其他需要更改的内容?(我是 Rails 新手;))