2012-05-31 75 views
0

獲取試圖intall軌管理時出現以下錯誤......假設它的模型關聯錯誤,但我不能弄明白..型號關聯錯誤的Rails聯繫

/Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/inheritance.rb:119:in `compute_type': uninitialized constant Interest::Person (NameError) 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_record/reflection.rb:172:in `klass' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/rails_admin-0.0.3/lib/rails_admin/adapters/active_record.rb:218:in `association_model_lookup' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/rails_admin-0.0.3/lib/rails_admin/adapters/active_record.rb:63:in `block (2 levels) in associations' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/rails_admin-0.0.3/lib/rails_admin/config/fields/association.rb:59:in `call' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/rails_admin-0.0.3/lib/rails_admin/config/fields/association.rb:59:in `associated_model_config' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/rails_admin-0.0.3/lib/rails_admin/config/fields/association.rb:34:in `block in <class:Association>' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/rails_admin-0.0.3/lib/rails_admin/config/configurable.rb:68:in `instance_eval' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/rails_admin-0.0.3/lib/rails_admin/config/configurable.rb:68:in `block in register_instance_option' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/rails_admin-0.0.3/lib/rails_admin/config/configurable.rb:42:in `block in register_instance_option' 
    from (erb):86:in `block (2 levels) in template' 
    from (erb):85:in `map' 
    from (erb):85:in `block in template' 
    from (erb):82:in `map' 
    from (erb):82:in `template' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/erb.rb:753:in `eval' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/erb.rb:753:in `result' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/actions/file_manipulation.rb:111:in `block in template' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/actions/create_file.rb:54:in `call' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/actions/create_file.rb:54:in `render' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/actions/create_file.rb:47:in `identical?' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/actions/create_file.rb:73:in `on_conflict_behavior' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/actions/empty_directory.rb:111:in `invoke_with_conflict_check' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/actions/create_file.rb:61:in `invoke!' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/actions.rb:95:in `action' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/actions/create_file.rb:26:in `create_file' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/actions/file_manipulation.rb:110:in `template' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/rails_admin-0.0.3/lib/generators/rails_admin/install_generator.rb:62:in `install' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/task.rb:22:in `run' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `block in invoke_all' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `each' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `map' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `invoke_all' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/group.rb:226:in `dispatch' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/base.rb:389:in `start' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/generators.rb:170:in `invoke' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands/generate.rb:12:in `<top (required)>' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `block in require' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require' 
    from /Users/nelsonkeating/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/commands.rb:29:in `<top (required)>' 
    from script/rails:6:in `require' 
    from script/rails:6:in `<main>' 

模型

class User < ActiveRecord::Base 
    has_many :friends 
    has_many :person_interests, :as => :person 
    has_many :interests, :through => :person_interests 
    has_many :user_holidays 
    has_many :holidays, :through => :user_holidays 
    has_many :anniversaries 
end 

class PersonInterest < ActiveRecord::Base 
    attr_accessible :person_id, :person_type, :interest_ids 
    belongs_to :interest 
    belongs_to :person, :polymorphic => true 

end 

class Interest < ActiveRecord::Base 
    attr_accessible :name 
    has_many :person_interests 
    has_many :people, :through => :person_interests 

end 

回答

4

問題是因爲您的has_many :people關聯在您的Interest型號中與此類似:

has_many :people, :through => :people_interest 

您的PersonInterest模型裏面的person關聯肯定夠用polymorphic,但has_many :through不尊重這一點。

因此,我會建議嘗試找到另一種方式讓所有的人。你可以這樣做哈克的方式:

def people 
    person_interests.includes(:person).map(&:people).flatten.uniq 
end 
+0

'person_interests.includes(:人).MAP(:人).flatten.uniq' – davidcelis