我想用gems populator和faker填充我的數據庫。我只是跟着railscast tutorial。如果我只按照教程,我的代碼如下所示:Rails應用程序中的Gems populator和faker調用錯誤
namespace :db do
desc "fill compact tables with sample data"
task :populate => :environment do
require 'populator'
require 'faker'
[RepositoryCompact, BuildCompact, JobCompact].each(&:delete_all)
RepositoryCompact.populate 10 do |repository|
repository.name = Faker::Name.name
repository.description = Populator.sentences(1)
repository.owner_name = Faker::Name.name
repository.url = Faker::Internet.url
i = 0
BuildCompact.populate 1..10 do |build|
build.config = Populator.sentences(1..3)
build.repository_compact_id = repository.id
build.number = i
i++
build.result = 0 || 1
build.finished_at = 2.years.ago..Time.now
JobCompact.populate 1..5 do |job|
job.build_compact_id = build.id
job.allow_failure = 0 || 1
#job.finished_at = build.finished_at-(2..100)
job.language = [ruby, php, java, c, python, rubinius, jruby]
job.version = [1.9 .. 2.5]
job.result = 0 || 1
end
end
end
end
end
如果我運行rake db:populate
的關係似乎不是由寶石(undefined method repository_compact_id=for #<Populator::Record:0x0000010177ffb8>
) 確認,但即使評論所有的東西,除了RepositoryCompact部分耙中止與Validation failed: Name has already been taken
我相信我樹立正確的模型和協會,以及。 是否有明顯的錯誤?
難道是寶石populator
太舊?
在此先感謝!