NoMethodError at / undefined method `admin?' for nil:NilClass
Opened this issue · 4 comments
ziweizhou commented
thanks for making up this gem, not sure why I am getting this error message
NoMethodError at / undefined method `admin?' for nil:NilClass
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.
sudosu commented
Hi! Thank you. Can you show me your TicketPolicy?
Pentium133 commented
RailsAdmin.config do |config|
config.current_user_method(&:current_user)
end
sudosu commented
config.authenticate_with do
warden.authenticate! scope: :user
end
fedelcar commented
Hi, just made a PR adding this to the readme