gregbell/active_admin — Issue #1075: Managing devise user model in Active Admin gives me headaches
Author: stigi
Created: 2012-02-26 19:49:11+00:00
State: open

Hello,

I have a set up with Rails (3.2), Devise (2.0.4), CanCan (1.6.7) and Active Admin (0.4.2).
I have 2 models: User and Role (with a HABTM relation)
Active Admin is configured with a filter that checks if the current user has the admin role like this:

def check_admin_role
return if current_user.role?(:admin)
flash[:notice] = "You need to be an admin to access this part of the application"
redirect_to root_path
end

I also can manage my roles without problems

ActiveAdmin.register Role do
end

When I try to manage my users...

ActiveAdmin.register User do
end

...problems start poping up:

...activerecord-3.2.1/lib/active_record/dynamic_matchers.rb:50:in `method_missing': undefined method `devise' for # (NoMethodError)
#full log: https://gist.github.com/4ba7cba19339a21b41fd

I figured that this might be because of the order of the initializers (`devise.rb` comes after `active_admin.rb`) so I renamed `devise.rb` to `_devise.rb`. I don't know if this solved the issue since a different problem now appears:

...activeadmin-0.4.2/lib/active_admin/namespace.rb:191:in `eval': uninitialized constant ActiveAdmin::Dashboards::ResourceController (NameError)
from /Users/ullrich/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.2/lib/active_admin/dashboards/dashboard_controller.rb:2:in `'
from /Users/ullrich/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.2/lib/active_admin/dashboards/dashboard_controller.rb:1:in `'
from (eval):1:in `generate_dashboard_controller'
from /Users/ullrich/.rbenv/versions/1.9.3-p125/lib/ruby/gems/1.9.1/gems/activeadmin-0.4.2/lib/active_admin/namespace.rb:191:in `eval'
#full log: https://gist.github.com/121d63ed83c951dbe576

Well, I don't know where this came from, but from looking inside the active admin code I figured there actually really isn't a class named `ActiveAdmin::Dashboards::ResourceController`. So I had a look at `namespace.rb`which appeared further down in the stack trace and added `require 'active_admin/resource_controller'`. The error vanishes, but a new one poped up:

...activeadmin-0.4.2/lib/active_admin/base_controller/menu.rb:2:in `': uninitialized constant InheritedResources::Base (NameError)
#full log: https://gist.github.com/888c6b123ca96fc7a436

Here's where my luck ended... I tried adding `gem 'inherited_resources', '1.3.0'` to active admins `Gemfile`and to the `Gemfile`of my app, but no effect.
I replaced `gem 'activeadmin'` with `gem 'activeadmin', :require => 'inherited_resources'` in my Gemfile and came up with a different error:

...initializers/active_admin.rb:1:in `': uninitialized constant ActiveAdmin (NameError)
#full log: https://gist.github.com/77d659d4db622cf822c5

That's where I stopped since I think there's something generally wrong here since I'm too far away from my initial problem.

Does anyone see where I went wrong?

Disclaimer: I'm very much still learning Ruby and Rails.

Thanks for all help!