AlexBrand
AlexBrand

Reputation: 12429

ActiveAdmin uninitialized constant

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>

Upvotes: 6

Views: 11908

Answers (7)

Rakesh Rajput
Rakesh Rajput

Reputation: 11

Simply go to your routes and remove the active_admin routes and also run rails destroy active_admin:install

Upvotes: 0

Manoj Datt
Manoj Datt

Reputation: 388

uncomment the (gem 'therubyracer', platforms: :ruby) gem from gem-file then bundle..it works

Upvotes: 0

Pooyan Khosravi
Pooyan Khosravi

Reputation: 5039

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.

Upvotes: 12

Martin Bjeldbak Madsen
Martin Bjeldbak Madsen

Reputation: 180

@alexBrand's solution didn't work for me.

Instead, adding require 'activeadmin/cancan_adapter' inside the configuration block worked for me.

Upvotes: 0

Kareem Hashem
Kareem Hashem

Reputation: 1077

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

Upvotes: 10

AlexBrand
AlexBrand

Reputation: 12429

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

Upvotes: 7

sameera207
sameera207

Reputation: 16629

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

try running bundle install in production env

Upvotes: 1

Related Questions