English 中文(简体)
铁路3 - 工厂定义中未开端的固定
原标题:rails3 - uninitialized constant in factory definition

<代码>因子_女孩不承认我界定的模范名称,我需要参考,因为我需要一个子级。 这在铁路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
最佳回答

在再次查阅<代码>因果-女生文件后,我认识到,你可以使用体格或班级固定的方式指定一个班级。 因此,我尝试使用一种扼杀手段,并努力:

Factory.define :interest, :class => "Term::Interest" do |f|
  f.name {"#{Factory.next(:lipsum_word)}ing"}
end

此外,还就修课发表了意见。 我最初这样做是为了让这些班级组织起来稍微多,但鉴于所创造的复杂性(特别是为了路线),我只想把每个班子移至自己的示范档案。 (如果我不把他们放在单独档案中,就不给他们以任何身份,那么,如果父母的班子在前面提到(用该档案装上)的话,铁路似乎有时无法找到子。

问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签