0

这是我运行安装程序时显示的内容。输出很奇怪,有一些关于外键和反射的抱怨。source_reflection 为零?关于修复的任何想法?

此外,除非我添加一堆额外的运球来填写此表格,否则不让我发布这个问题真的很烦人。来吧!

 -  Hello, RailsAdmin installer will help you set things up!
       -  I need to work with Devise, let's look at a few things first:
       -  Checking for a current installation of devise...
       -  Found it!
       -  Looks like you've already installed it, good!
       ?  Where do you want to mount rails_admin? Press <enter> for [admin] > 
    gsub  config/routes.rb
   route  mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'
       -  And you already set it up, good! We just need to know about your user model name...
       -  We found 'user' (should be one of 'user', 'admin', etc.)
       ?  Correct Devise model name if needed. Press <enter> for [user] > admin
       -  Now setting up devise with user model name 'admin':
generate  devise
  invoke  active_record
  create    db/migrate/20131114155103_add_devise_to_admins.rb
  insert    app/models/admin.rb
   route  devise_for :admins
       -  Now you'll need an initializer...
  create  config/initializers/rails_admin.rb
/Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/activerecord-4.0.0/lib/active_record/reflection.rb:401:in `rescue in foreign_key': ActiveRecord::Reflection::ThroughReflection#foreign_key delegated to source_reflection.foreign_key, but source_reflection is nil: #<ActiveRecord::Reflection::ThroughReflection:0x007f87de0c5bd0 @macro=:has_many, @name=:transactions, @scope=nil, @options={:through=>:locatables}, @active_record=Address(id: integer, street: string, city: string, state: string, zip: string, country: string, created_at: datetime, updated_at: datetime, latitude: float, longitude: float), @plural_name="transactions", @collection=true, @source_reflection_names=[:transaction, :transactions], @through_reflection=#<ActiveRecord::Reflection::AssociationReflection:0x007f87dafbb670 @macro=:has_many, @name=:locatables, @scope=nil, @options={}, @active_record=Address(id: integer, street: string, city: string, state: string, zip: string, country: string, created_at: datetime, updated_at: datetime, latitude: float, longitude: float), @plural_name="locatables", @collection=true, @foreign_key="address_id", @class_name="Locatable", @klass=Locatable(id: integer, owner_id: integer, owner_type: string, address_id: integer, created_at: datetime, updated_at: datetime, pickup: boolean, kind: string)>, @source_reflection=nil> (RuntimeError)
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/activerecord-4.0.0/lib/active_record/reflection.rb:397:in `foreign_key'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/rails_admin/adapters/active_record.rb:306:in `association_foreign_key_lookup'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/rails_admin/adapters/active_record.rb:72:in `block in associations'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/rails_admin/adapters/active_record.rb:65:in `map'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/rails_admin/adapters/active_record.rb:65:in `associations'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/rails_admin/config/fields/factories/association.rb:6:in `block in <top (required)>'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/rails_admin/config/fields.rb:54:in `call'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/rails_admin/config/fields.rb:54:in `block (2 levels) in factory'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/rails_admin/config/fields.rb:54:in `each'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/rails_admin/config/fields.rb:54:in `find'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/rails_admin/config/fields.rb:54:in `block in factory'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/rails_admin/config/fields.rb:50:in `each'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/rails_admin/config/fields.rb:50:in `factory'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/rails_admin/config/has_fields.rb:130:in `_fields'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/rails_admin/config/has_fields.rb:128:in `_fields'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/rails_admin/config/has_fields.rb:108:in `all_fields'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/rails_admin/config/has_fields.rb:83:in `fields'
    from (erb):64:in `block in template'
    from (erb):53:in `map'
    from (erb):53:in `template'
    from /Users/JCC/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/erb.rb:849:in `eval'
    from /Users/JCC/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/erb.rb:849:in `result'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/actions/file_manipulation.rb:117:in `block in template'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/actions/create_file.rb:54:in `call'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/actions/create_file.rb:54:in `render'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/actions/create_file.rb:63:in `block (2 levels) in invoke!'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/actions/create_file.rb:63:in `open'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/actions/create_file.rb:63:in `block in invoke!'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/actions/empty_directory.rb:117:in `call'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/actions/empty_directory.rb:117:in `invoke_with_conflict_check'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/actions/create_file.rb:61:in `invoke!'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/actions.rb:95:in `action'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/actions/create_file.rb:26:in `create_file'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/actions/file_manipulation.rb:116:in `template'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/rails_admin-0.5.0/lib/generators/rails_admin/install_generator.rb:75:in `install'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/command.rb:27:in `run'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/invocation.rb:127:in `block in invoke_all'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/invocation.rb:127:in `each'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/invocation.rb:127:in `map'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/invocation.rb:127:in `invoke_all'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/group.rb:233:in `dispatch'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/railties-4.0.0/lib/rails/generators.rb:156:in `invoke'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/railties-4.0.0/lib/rails/commands/generate.rb:11:in `<top (required)>'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
    from /Users/JCC/.rvm/gems/ruby-2.0.0-p247@testing/gems/railties-4.0.0/lib/rails/commands.rb:49:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'
4

1 回答 1

0

这个错误花了我一段时间才弄清楚。另一个 SO 答案以及一些外部帮助为我提供了有关导致错误的线索。那就是这里的反射错误与多态关联

另一个帮助我的 SO 是了解您需要如何使 rails 的关联更清晰,或者在这种情况下,rails admin,因为它需要知道所有关系才能将其呈现给管理员。:rails 中的源选项

问题是我有一个多态关联,这对源的轨道不是很清楚。一旦我消除了 Rails 管理员困惑的根源,我就能够毫无错误地继续进行。

两个注意事项:

  1. 如果您已经使用 devise 创建了管理类,则必须编辑或删除 rails admin 自动生成的迁移文件。它称为 AddDeviseToAdmins。确保对其进行编辑,使其不会重复您当前管理表中已有的字段。就我而言,我完全删除了该文件,因为我的默认设计生成的管理表已经包含了那里的所有内容。

  2. 第一个 SO 的第二个选项是 :source-type => "something",它输入错误。它应该是 :source_type => "something"。使用下划线而不是破折号。

于 2013-11-15T21:12:33.640 回答