<代码>因子_女孩代码>不承认我界定的模范名称,我需要参考,因为我需要一个子级。 这在铁路2号,但我向铁路3号。
工厂定义:
Factory.define :interest, :class => Term::Interest do |f|
f.name {"#{Factory.next(:lipsum_word)}ing"}
end
术语表
class Term < ActiveRecord::Base
belongs_to :category
class Interest < Term
end
class Award < Term
end
end
误差和跟踪:
$ rake db:data:load --trace
(in /Users/glurban/code/recruitd)
rake aborted!
uninitialized constant Term
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/rspec-core-2.4.0/lib/rspec/core/backward_compatibility.rb:20:in `const_missing
/Users/glurban/code/recruitd/test/factories/factories.rb:316:in `<top (required)>
/Users/glurban/code/recruitd/lib/tasks/use_factories.rake:2:in `<top (required)>
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/railties-3.0.0/lib/rails/engine.rb:131:in `block in load_tasks
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/railties-3.0.0/lib/rails/engine.rb:131:in `each
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/railties-3.0.0/lib/rails/engine.rb:131:in `load_tasks
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/railties-3.0.0/lib/rails/application.rb:141:in `load_tasks
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/railties-3.0.0/lib/rails/application.rb:77:in `method_missing
/Users/glurban/code/recruitd/Rakefile:7:in `<top (required)>
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/rake-0.8.7/lib/rake.rb:2383:in `load
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/rake-0.8.7/lib/rake.rb:2383:in `raw_load_rakefile
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/rake-0.8.7/lib/rake.rb:2017:in `block in load_rakefile
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/rake-0.8.7/lib/rake.rb:2016:in `load_rakefile
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/rake-0.8.7/lib/rake.rb:2000:in `block in run
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/rake-0.8.7/lib/rake.rb:1998:in `run
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/rake-0.8.7/bin/rake:31:in `<top (required)>
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/bin/rake:19:in `load
/Users/glurban/.rvm/gems/ruby-1.9.2-rc2/bin/rake:19:in `<main>
我尝试在<条码>上添加<条码>require_dependency term 至上<条码>要素.rb条码>,但随后我收到。
Glens-MacBook-Pro:test glurban$ rake db:data:load
(in /Users/glurban/code/recruitd)
rake aborted!
No such file to load -- term
什么?
Edit:作为对评论的回应,是,它只在 r上发生,而不是在 con里发生:
$ rails c
Loading development environment (Rails 3.0.0)
ruby-1.9.2-rc2 > Factory(:term)
=> #<Term id: 3, type: nil, name: "Proud to be a Recruitd user", location: nil, category_id: nil, description: nil, url: nil, created_at: "2011-01-06 21:30:14", updated_at: "2011-01-06 21:30:14">
ruby-1.9.2-rc2 > Factory(:interest)
=> #<Term::Interest id: 4, type: "Term::Interest", name: "siting", location: nil, category_id: nil, description: nil, url: nil, created_at: "2011-01-06 21:30:18", updated_at: "2011-01-06 21:30:18">
习惯任务定义:
require factory_girl
require File.expand_path("test/factories/factories.rb")
namespace :db do
namespace :data do
desc "Load sample data"
task :load => :environment do |t|
create_students
...
create_student_files_and_feeds
puts "Completed loading sample data."
end
end
end
def create_interests
data_fetch("interests").each do |input|
Factory(:interest, :name => input.strip)
end
puts "Created interests"
end