Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to use devise with Adminitrate?

Oyewole Samuel asked in Gems / Libraries

Great tuts, please how can i use this with devise? when i run rails generate administrate:install, it generate error... says admin is not a class, already have a devise called admin, also have a view admin, please how can i manage this... want admin to authenticate before using login. Please how can this be achieve

Reply

Great question. If you want to use the existing Admin model from devise, all you need to do is add before_action :authenticate_user! to your admin controllers to force the admin user to be logged in. That should be it!

Reply

Thanks @chris for quick response, appreciated. Fully understand your message but the challenge here is that i've generated two devise 'User' & 'Admin', generating 'administrate:install' split error...

λ rails generate administrate:install
DL is deprecated, please use Fiddle
      create  app/controllers/admin/application_controller.rb
       route  namespace :admin do
    DashboardManifest::DASHBOARDS.each do |dashboard_resource|
      resources dashboard_resource
    end

    root controller: DashboardManifest::ROOT_DASHBOARD, action: :index
  end
[WARNING] Could not load generator "generators/administrate/manifest/manifest_generator". Error: Admin is not a class.
C:/Ruby21/workspace/studio_versity/app/models/admin.rb:1:in `<top (required)>'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:457:in `load'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:457:in `block in load_file'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:647:in `new_constants_in'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:456:in `load_file'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:354:in `require_or_load'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:317:in `depend_on'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:233:in `require_dependency'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/engine.rb:472:in `block (2 levels) in eager_load!'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/engine.rb:471:in `each'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/engine.rb:471:in `block in eager_load!'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/engine.rb:469:in `each'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/engine.rb:469:in `eager_load!'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/administrate-0.1.3/lib/generators/administrate/manifest/manifest_generator.rb:1:in `<top (required)>'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/generators.rb:332:in `block (2 levels) in lookup'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/generators.rb:328:in `each'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/generators.rb:328:in `block in lookup'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/generators.rb:327:in `each'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/generators.rb:327:in `lookup'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/generators.rb:138:in `find_by_namespace'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/generators.rb:155:in `invoke'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/administrate-0.1.3/lib/administrate/generator_helpers.rb:4:in `call_generator'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/administrate-0.1.3/lib/generators/administrate/install/install_generator.rb:41:in `manifest'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/administrate-0.1.3/lib/generators/administrate/install/install_generator.rb:36:in `dashboard_resources'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/administrate-0.1.3/lib/generators/administrate/install/install_generator.rb:32:in `singular_dashboard_resources'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/administrate-0.1.3/lib/generators/administrate/install/install_generator.rb:24:in `run_dashboard_generators'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/generators.rb:157:in `invoke'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/commands/generate.rb:13:in `<top (required)>'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:123:in `require_command!'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:130:in `generate_or_destroy'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:50:in `generate'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
[WARNING] Please install gem 'therubyracer' to use Less.
Could not find generator 'administrate:manifest'. Maybe you meant 'administrate:view', 'administrate:assets' or 'administrate:views'
Run `rails generate --help` for more options.
C:/Ruby21/lib/ruby/gems/2.1.0/gems/administrate-0.1.3/lib/generators/administrate/install/install_generator.rb:44:in `manifest': uninitialized constant Administrate::Generators::InstallGenerator::DashboardManifest (NameError)
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/administrate-0.1.3/lib/generators/administrate/install/install_generator.rb:36:in `dashboard_resources'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/administrate-0.1.3/lib/generators/administrate/install/install_generator.rb:32:in `singular_dashboard_resources'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/administrate-0.1.3/lib/generators/administrate/install/install_generator.rb:24:in `run_dashboard_generators'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/generators.rb:157:in `invoke'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/commands/generate.rb:13:in `<top (required)>'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:123:in `require_command!'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:130:in `generate_or_destroy'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:50:in `generate'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
        from C:/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'

Please what's the solution?

Reply

What is the contents of your app/models/admin.rb file? It sounds like the Admin class isn't defined in there for some reason.

Reply

Thanks @chris, below are the contents contained in admin.rb

class Admin < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable 
  devise :database_authenticatable, :recoverable,
         :rememberable, :trackable, :validatable
end

Thanks

Reply

That definitely looks right. Huh. I'm not sure what is causing that.

One thing you could try is removing the Admin class and using AdminUser as the name instead to see if that does the trick.

Reply

Thanks @chris, i'll do exactly and give you a feedback later. Thanks

Reply

Thanks @chris, i found the solution here ==> https://github.com/thoughtbot/administrate/issues/225

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,563+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.