JamesRocky
JamesRocky

Reputation: 721

Rails: NoMethodError in RailsAdmin::MainController#dashboard

I was setting up authorization using the code below and got an error. I'm using devise

undefined method `is_admin?' for #<User:0x007f803734ba48>

I've already setup the admin user in the console but I'm having issues testing out users trying to log in.

    RailsAdmin.config do |config|
      config.authorize_with do
        redirect_to main_app.root_path unless warden.user.is_admin?
      end
    end

https://github.com/sferik/rails_admin/wiki/Authorization

Upvotes: 0

Views: 2072

Answers (2)

Vincent J. Michuki
Vincent J. Michuki

Reputation: 549

This worked for me: Include a boolean field in your users table and name it admin

Then use this:

RailsAdmin.config do |config|
  config.authenticate_with do
    warden.authenticate! scope: :user
  end
  config.current_user_method(&:current_user)

  config.authorize_with do
    redirect_to main_app.root_path unless current_user.admin == true
  end
end

Upvotes: 2

nesiseka
nesiseka

Reputation: 1318

Are you using Warden? On the same page I've found some custom authorization. Have you tried that?

Upvotes: 1

Related Questions