Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paper_trail and Rails_Admin: NameError - uninitialized constant Version

I have recently upgraded paper_trail to version 3.0.0 and met this error:

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>'

I can't get how to solve it. When I used version 2.7.1 everything was great. I also use rails 3.2.16 and rails_admin 0.4.9. My migration is:

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

And in my models i attach paper_trail:

class Page < ActiveRecord::Base
  has_paper_trail
end

Any idea how to fix that?

like image 232
ExiRe Avatar asked Dec 26 '13 15:12

ExiRe


2 Answers

I would say that PaperTrail 3.0 has its Version class namespaced as PaperTrail::Version, whereas the RailsAdmin Paper Trail adapter is looking for Version in the global namespace and not finding it. Probably a quick fix to fork the RailsAdmin gem and fix the problem:

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

From your stack trace, the offending line of code is line 48 but really line 41. Probably would fix it simply to change '::Version' to 'PaperTrail::Version'.

like image 108
davidfurber Avatar answered Sep 28 '22 20:09

davidfurber


Nowdays (since 0.6.1 for sure) you don't need to patch rails_admin. You need to specify just one option in config/rails_admin.rb:

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

And that is all.

like image 41
ExiRe Avatar answered Sep 28 '22 20:09

ExiRe