Paper_trail和Rails_Admin:NameError - 未初始化的常量版本

时间:2013-12-26 15:19:40

标签: ruby-on-rails ruby-on-rails-3 rails-admin paper-trail-gem

我最近将paper_trail升级到版本3.0.0并遇到了此错误:

Started GET "/admin/" for 127.0.0.1 at 2013-12-26 18:55:59 +0400
Processing by RailsAdmin::MainController#dashboard as HTML
  Admin Load (0.2ms)  SELECT "admins".* FROM "admins" WHERE "admins"."id" = 1 LIMIT 1
Completed 500 Internal Server Error in 27.5ms

NameError - uninitialized constant Version:
  (gem) activesupport-3.2.16/lib/active_support/dependencies.rb:520:in `load_missing_constant'
  (gem) activesupport-3.2.16/lib/active_support/dependencies.rb:192:in `block in const_missing'
  (gem) activesupport-3.2.16/lib/active_support/dependencies.rb:190:in `const_missing'
  (gem) rails_admin-0.4.9/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb:48:in `latest'
  (gem) rails_admin-0.4.9/lib/rails_admin/config/actions/dashboard.rb:17:in `block (2 levels) in <class:Dashboard>'
  (eval):8:in `dashboard'
  (gem) actionpack-3.2.16/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  (gem) actionpack-3.2.16/lib/abstract_controller/base.rb:167:in `process_action'
  (gem) actionpack-3.2.16/lib/action_controller/metal/rendering.rb:10:in `process_action'
  (gem) actionpack-3.2.16/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
  (gem) activesupport-3.2.16/lib/active_support/callbacks.rb:535:in `_run__3295254136304352753__process_action__548262850884401428__callbacks'
  (gem) activesupport-3.2.16/lib/active_support/callbacks.rb:405:in `__run_callback'
  (gem) activesupport-3.2.16/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
  (gem) activesupport-3.2.16/lib/active_support/callbacks.rb:81:in `run_callbacks'
  (gem) actionpack-3.2.16/lib/abstract_controller/callbacks.rb:17:in `process_action'
  (gem) actionpack-3.2.16/lib/action_controller/metal/rescue.rb:29:in `process_action'
  (gem) actionpack-3.2.16/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
  (gem) activesupport-3.2.16/lib/active_support/notifications.rb:123:in `block in instrument'
  (gem) activesupport-3.2.16/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  (gem) activesupport-3.2.16/lib/active_support/notifications.rb:123:in `instrument'
  (gem) actionpack-3.2.16/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
  (gem) actionpack-3.2.16/lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
  (gem) activerecord-3.2.16/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  (gem) actionpack-3.2.16/lib/abstract_controller/base.rb:121:in `process'
  (gem) actionpack-3.2.16/lib/abstract_controller/rendering.rb:45:in `process'
  (gem) actionpack-3.2.16/lib/action_controller/metal.rb:203:in `dispatch'
  (gem) actionpack-3.2.16/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
  (gem) actionpack-3.2.16/lib/action_controller/metal.rb:246:in `block in action'
  (gem) actionpack-3.2.16/lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
  (gem) actionpack-3.2.16/lib/action_dispatch/routing/route_set.rb:36:in `call'
  (gem) journey-1.0.4/lib/journey/router.rb:68:in `block in call'
  (gem) journey-1.0.4/lib/journey/router.rb:56:in `call'
  (gem) actionpack-3.2.16/lib/action_dispatch/routing/route_set.rb:608:in `call'
  (gem) railties-3.2.16/lib/rails/engine.rb:484:in `call'
  (gem) railties-3.2.16/lib/rails/railtie/configurable.rb:30:in `method_missing'
  (gem) journey-1.0.4/lib/journey/router.rb:68:in `block in call'
  (gem) journey-1.0.4/lib/journey/router.rb:56:in `call'
  (gem) actionpack-3.2.16/lib/action_dispatch/routing/route_set.rb:608:in `call'
  (gem) rack-pjax-0.7.0/lib/rack/pjax.rb:12:in `call'
  (gem) bullet-4.6.0/lib/bullet/rack.rb:13:in `call'
  (gem) meta_request-0.2.8/lib/meta_request/middlewares/app_request_handler.rb:13:in `call'
  (gem) rack-contrib-1.1.0/lib/rack/contrib/response_headers.rb:17:in `call'
  (gem) meta_request-0.2.8/lib/meta_request/middlewares/headers.rb:16:in `call'
  (gem) meta_request-0.2.8/lib/meta_request/middlewares/meta_request_handler.rb:13:in `call'
  (gem) request_store-1.0.5/lib/request_store/middleware.rb:9:in `call'
  (gem) galetahub-simple_captcha-0.1.5/lib/simple_captcha/middleware.rb:20:in `call'
  (gem) warden-1.2.3/lib/warden/manager.rb:35:in `block in call'
  (gem) warden-1.2.3/lib/warden/manager.rb:34:in `call'
  (gem) actionpack-3.2.16/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  (gem) rack-1.4.5/lib/rack/etag.rb:23:in `call'
  (gem) rack-1.4.5/lib/rack/conditionalget.rb:25:in `call'
  (gem) actionpack-3.2.16/lib/action_dispatch/middleware/head.rb:14:in `call'
  (gem) remotipart-1.2.1/lib/remotipart/middleware.rb:27:in `call'
  (gem) actionpack-3.2.16/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  (gem) actionpack-3.2.16/lib/action_dispatch/middleware/flash.rb:242:in `call'
  (gem) rack-1.4.5/lib/rack/session/abstract/id.rb:210:in `context'
  (gem) rack-1.4.5/lib/rack/session/abstract/id.rb:205:in `call'
  (gem) actionpack-3.2.16/lib/action_dispatch/middleware/cookies.rb:341:in `call'
  (gem) activerecord-3.2.16/lib/active_record/query_cache.rb:64:in `call'
  (gem) activerecord-3.2.16/lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
  (gem) actionpack-3.2.16/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  (gem) activesupport-3.2.16/lib/active_support/callbacks.rb:405:in `_run__689952341354032436__call__3266767755508832131__callbacks'
  (gem) activesupport-3.2.16/lib/active_support/callbacks.rb:405:in `__run_callback'
  (gem) activesupport-3.2.16/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  (gem) activesupport-3.2.16/lib/active_support/callbacks.rb:81:in `run_callbacks'
  (gem) actionpack-3.2.16/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  (gem) actionpack-3.2.16/lib/action_dispatch/middleware/reloader.rb:65:in `call'
  (gem) actionpack-3.2.16/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  (gem) better_errors-0.7.2/lib/better_errors/middleware.rb:84:in `protected_app_call'
  (gem) better_errors-0.7.2/lib/better_errors/middleware.rb:79:in `better_errors_call'
  (gem) better_errors-0.7.2/lib/better_errors/middleware.rb:56:in `call'
  (gem) actionpack-3.2.16/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  (gem) actionpack-3.2.16/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  (gem) railties-3.2.16/lib/rails/rack/logger.rb:32:in `call_app'
  (gem) railties-3.2.16/lib/rails/rack/logger.rb:16:in `block in call'
  (gem) activesupport-3.2.16/lib/active_support/tagged_logging.rb:22:in `tagged'
  (gem) railties-3.2.16/lib/rails/rack/logger.rb:16:in `call'
  (gem) quiet_assets-1.0.2/lib/quiet_assets.rb:18:in `call_with_quiet_assets'
  (gem) actionpack-3.2.16/lib/action_dispatch/middleware/request_id.rb:22:in `call'
  (gem) rack-1.4.5/lib/rack/methodoverride.rb:21:in `call'
  (gem) rack-1.4.5/lib/rack/runtime.rb:17:in `call'
  (gem) activesupport-3.2.16/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  (gem) rack-1.4.5/lib/rack/lock.rb:15:in `call'
  (gem) actionpack-3.2.16/lib/action_dispatch/middleware/static.rb:63:in `call'
  (gem) rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward'
  (gem) rack-cache-1.2/lib/rack/cache/context.rb:245:in `fetch'
  (gem) rack-cache-1.2/lib/rack/cache/context.rb:185:in `lookup'
  (gem) rack-cache-1.2/lib/rack/cache/context.rb:66:in `call!'
  (gem) rack-cache-1.2/lib/rack/cache/context.rb:51:in `call'
  (gem) railties-3.2.16/lib/rails/engine.rb:484:in `call'
  (gem) railties-3.2.16/lib/rails/application.rb:231:in `call'
  (gem) rack-1.4.5/lib/rack/content_length.rb:14:in `call'
  (gem) railties-3.2.16/lib/rails/rack/log_tailer.rb:17:in `call'
  (gem) thin-1.5.1/lib/thin/connection.rb:81:in `block in pre_process'
  (gem) thin-1.5.1/lib/thin/connection.rb:79:in `pre_process'
  (gem) thin-1.5.1/lib/thin/connection.rb:54:in `process'
  (gem) thin-1.5.1/lib/thin/connection.rb:39:in `receive_data'
  (gem) eventmachine-1.0.3/lib/eventmachine.rb:187:in `run'
  (gem) thin-1.5.1/lib/thin/backends/base.rb:63:in `start'
  (gem) thin-1.5.1/lib/thin/server.rb:159:in `start'
  (gem) rack-1.4.5/lib/rack/handler/thin.rb:13:in `run'
  (gem) rack-1.4.5/lib/rack/server.rb:268:in `start'
  (gem) railties-3.2.16/lib/rails/commands/server.rb:70:in `start'
  (gem) railties-3.2.16/lib/rails/commands.rb:55:in `block in <top (required)>'
  (gem) railties-3.2.16/lib/rails/commands.rb:50:in `<top (required)>'
  script/rails:6:in `<main>'

我无法理解如何解决它。当我使用版本2.7.1时,一切都很棒。我还使用rails 3.2.16和rails_admin 0.4.9。我的迁移是:

class CreateVersions < ActiveRecord::Migration
  def self.up
    create_table :versions do |t|
      t.string   :item_type, :null => false
      t.integer  :item_id,   :null => false
      t.string   :event,     :null => false
      t.string   :whodunnit
      t.text     :object
      t.datetime :created_at
    end
    add_index :versions, [:item_type, :item_id]
  end

  def self.down
    remove_index :versions, [:item_type, :item_id]
    drop_table :versions
  end
end

在我的模特中,我附上了paper_trail:

class Page < ActiveRecord::Base
  has_paper_trail
end

知道如何解决这个问题吗?

2 个答案:

答案 0 :(得分:2)

我想说PaperTrail 3.0将其Version类命名为PaperTrail :: Version,而RailsAdmin Paper Trail适配器在全局命名空间中寻找Version并且没有找到它。可能是快速解决RailsAdmin gem并解决问题的方法:

https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb

从您的堆栈跟踪中,有问题的代码行是第48行,但实际上是第41行。可能会修改它只是为了更改&#39; :: Version&#39; to PaperTrail ::版本&#39;。

答案 1 :(得分:1)

Nowdays(因为0.6.1肯定)你不需要修补rails_admin。您只需在config/rails_admin.rb中指定一个选项:

  config.audit_with :paper_trail, 'Admin', 'PaperTrail::Version' # PaperTrail >= 3.0.0

就是这样。