2
votes

I am trying to use rails_admin_pundit to add role based access to rails_admin.

I am getting this error when I click on the users table in the rails_admin.

ArgumentError at /user. User(id: integer, email: string, ... 'shortened' ...role: integer) is not an ActiveRecord::Relation

I created an app using:
https://github.com/RailsApps/rails-devise-pundit

and followed the usage instructions at:
https://github.com/sudosu/rails_admin_pundit

This is in my user_policy.rb just to get things started...

def rails_admin?(action)
  case action
    when :destroy, :new
      false
    else
      @current_user.admin!
  end
end

Attached are a couple apps with the error, and a screen shot of what I see just before I press the Users model name link.

app with the error..

error file and screenshot

another app with the same error

Not needed: dropbox link... link to screenshot, error page, and two apps that I have this problem in...

  • I can get pundit to work outside of rails_admin
  • I am logged in as admin
  • I have googled the web for this error or similar issues.

Can someone help me with this?

1

1 Answers

1
votes

When we generate the code we have:

class Scope < Scope
    def resolve
      scope
    end
  end

So, instead that we need to define the scope

class Scope < Scope
  def resolve      
    if @user.role.description == 'admin' 
      User.all
    else
      User.where(id: @user.id)
    end
  end
end