8

I'm getting an error while trying to run my app, having recently installed ActiveAdmin. It was working fine, but, after idling for a while, suddenly it isn't!

In my gem file:

gem 'activeadmin'

In my routes:

  devise_for :admin_users, ActiveAdmin::Devise.config

  ActiveAdmin.routes(self) 

And in my admin_user.rb

ActiveAdmin.register AdminUser do     
  index do                            
    column :email                     
    column :current_sign_in_at        
    column :last_sign_in_at           
    column :sign_in_count             
    default_actions                   
  end   etc....

The error when trying to run:

NameError: uninitialized constant AdminUser
~/Desktop/Sites/Fleetnation/app/admin/admin_user.rb:1:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.11/lib/active_support/inflector/methods.rb:230:in `block in constantize'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.11/lib/active_support/inflector/methods.rb:229:in `each'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.11/lib/active_support/inflector/methods.rb:229:in `constantize'
...

Anyone got any ideas? Would be much appreciated.

Benji Lanyado
  • 239
  • 1
  • 3
  • 12
  • did you migrate your database? does app/models/admin_user.rb exist? – Jesse Wolgamott Jun 03 '13 at 21:35
  • Yup... definitely - the error is triggered on the first line of admin_user.rb file (ActiveAdmin.register AdminUser do etc..) which is in my admin folder. – Benji Lanyado Jun 03 '13 at 21:39
  • Nope, you're missing a step. app/admin/admin_user is the Dashboard -- but you actually have to have an app/models/admin_user.rb that is an ActiveRecord::Base object. – Jesse Wolgamott Jun 03 '13 at 21:48
  • Ah, my bad - an oversight. the `app/models/admin_user.rb` is indeed there, and always had been. And now, without having changed anything, the app is working. This must be a local error of some type. Odd. Thanks for your help though! – Benji Lanyado Jun 04 '13 at 09:27

3 Answers3

11

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

andreofthecape
  • 1,166
  • 11
  • 24
5

This error will be thrown any time your model has an erroneous association in it. If you changed any associations, but forget to update your model's file, you will get this error.

Double check your model files. Open active admin locally to see what error it gives you (localhost:3000/admin). It will usually say uninitialized constant MyModel:MyBadAssociation, so helps you diagnose the error.

Don P
  • 60,113
  • 114
  • 300
  • 432
-3

Renaming app/models/admin_user.rb to app/models/admin_users.rb helped me.

sashazykov
  • 13
  • 3