尝试安装rails admin时出现以下错误...假设它是一个模型关联错误,但我无法弄清楚..
/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
答案 0 :(得分:4)
问题是因为您的has_many :people
模型中的Interest
关联是这样的:
has_many :people, :through => :people_interest
person
模型中的PersonInterest
关联肯定足够polymorphic
,但has_many :through
不尊重该关联。
因此,我建议尝试寻找另一种方法来吸引所有人。你可以这样做:
def people
person_interests.includes(:person).map(&:people).flatten.uniq
end