sudosu/rails_admin_pundit

NoMethodError at / undefined method `admin?' for nil:NilClass

Opened this issue · 4 comments

thanks for making up this gem, not sure why I am getting this error message

NoMethodError at / undefined method `admin?' for nil:NilClass

2014-12-02 12 33 57

my application_policy looks like following.

class ApplicationPolicy
  attr_reader :user, :record

  def initialize(user, record)
    raise Pundit::NotAuthorizedError, "must be logged in" unless user
    @user = user
    @record = record
    Rails.logger.info user
  end

  def index?
    user.admin? or user.staff?
  end

  def show?
    scope.where(:id => record.id).exists? and (user.admin? or user.staff?)
  end

  def create?
    user.admin? or user.staff?
  end

  def new?
    create?
  end

  def update?
    user.admin? or user.staff?
  end

  def edit?
    update?
  end

  def destroy?
    user.admin?
  end

  def rails_admin?(action)
    case action
      when :dashboard
        user.admin?
      when :index
        user.admin?
      when :show
        user.admin?
      when :new
        user.admin?
      when :edit
        user.admin?
      when :destroy
        user.admin?
      when :export
        user.admin?
      when :history
        user.admin?
      when :show_in_app
        user.admin?
      else
        raise ::Pundit::NotDefinedError, "unable to find policy #{action} for #{record}."
    end
  end

end

thanks.

Hi! Thank you. Can you show me your TicketPolicy?

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

Hi, just made a PR adding this to the readme