ActiveAdmin uninitialized constant

10,792

Solution 1

I added a require 'activeadmin' to my active_admin.rb initializer and it works!

Solution 2

What's Happening?

When requiring gems that define constants, like ActiveAdmin or ActiveAdmin::Comment, if for some reason during definition of that constant something goes wrong Bundler leaves that constant undefined and won't reraise the exception.

Possible Causes

ActiveAdmin depends on ExecJS and ExecJS needs a working JavaScript runtime. ExecJS will throw an error like this during definition of ActiveAdmin constant.

ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.

In this case, just install Node.js. sudo apt-get install nodejs

How to Debug Problems Like This

  1. Try to run Rails console. bundle exec rails console
  2. If that fails, try to manually require problematic gem inside irb and work through its dependencies.
  3. Require the gem or part if it that should be defined but isn't. When requiring manually Rubygems throw an exception describing the problem.
  4. Work through exceptions and fix them until the problem is resolved.

Solution 3

Try restarting rails server. Had similar problems which cleared up after a restart.

Solution 4

Probably you might not have run bundle install in your production env.

try running bundle install in production env

Share:
10,792
AlexBrand
Author by

AlexBrand

Updated on July 27, 2022

Comments

  • AlexBrand
    AlexBrand almost 2 years

    I am getting the following error after deploying my application to my VPS. ActiveAdmin works fine on my local development environment, but once I deploy using capistrano, it looks like the gem is not being installed?

    E, [2013-03-14T01:27:04.901577 #24972] ERROR -- : uninitialized constant ActiveAdmin (NameError)
    /home/deployer/apps/papaya/releases/20130314052558/config/initializers/active_admin.rb:1:in `<top (required)>'
    

    My gem file

    source 'https://rubygems.org'
    
    gem 'rails', '3.2.11'
    
    # Bundle edge Rails instead:
    # gem 'rails', :git => 'git://github.com/rails/rails.git'
    
    gem 'pg'
    gem 'bootstrap-sass'
    gem 'font-awesome-sass-rails'
    # gem 'acts_as_tree', :git => 'git://github.com/amerine/acts_as_tree.git'
    gem 'closure_tree'
    gem 'kaminari'
    gem 'friendly_id'
    gem 'slim'
    gem 'gmaps4rails'
    gem 'devise'
    gem 'omniauth'
    gem 'oauth2'
    gem 'omniauth-facebook'
    gem 'omniauth-twitter'
    gem 'simple_form'
    gem 'pg_search'
    gem 'stamp'
    gem 'acts-as-taggable-on', '~> 2.3.1'
    gem 'rmagick'
    gem 'carrierwave'
    gem 'select2-rails'
    # gem 'roo'
    gem 'activeadmin'
    gem "meta_search",    '>= 1.1.0.pre'
    
    # Gems used only for assets and not required
    # in production environments by default.
    group :assets do
      gem 'sass-rails',   '~> 3.2.3'
      gem 'coffee-rails', '~> 3.2.1'
    
      # See https://github.com/sstephenson/execjs#readme for more supported runtimes
      # gem 'therubyracer', :platforms => :ruby
      gem 'uglifier', '>= 1.0.3'
      gem 'compass-rails'
      gem 'turbo-sprockets-rails3'
    end
    

    I am able to run the console without a problem and require activeadmin

    deployer@pareto:~/apps/papaya/current$ RAILS_ENV=production bundle exec irb
    irb(main):001:0> require 'activeadmin'
    => true
    irb(main):002:0>
    
  • AlexBrand
    AlexBrand about 11 years
    Capistrano runs it when deploying
  • sameera207
    sameera207 about 11 years
    use 'bundler show activeadmi'n to see it really installed in prod
  • Alex Tonkonozhenko
    Alex Tonkonozhenko about 9 years
    I faced it too, so check your JS runtime.
  • Pooyan Khosravi
    Pooyan Khosravi about 9 years
    @AlexTonkonozhenko This is about how to debug rather than check your js runtime. These kind of errors happen too often, consider understanding the approach.
  • Alex Tonkonozhenko
    Alex Tonkonozhenko about 9 years
    I know, but I was surprised that ActiveAdmin depends on JS