I am using pundit gem to authorize in my system app. before to implement pundit I had my endpoint index like this:
def index
@cars = Car.all
render json: @cars
end
worked ok, but now with pundit, i made a change like this
def index
@cars = Car.all
authorize @cars
end
Now I am getting this error:
current_user must be defined before the impersonates method
Pundit works a little differently for the index route. typically you want to do exactly what you where trying
authorize @postbut we only pass one record.So for you:
this hits the following in pundit:
As for your error related to the current_user, is that coming from pundit? In pundit itself your current_user (from devise for example) will be just user, such that you can check
record.user == user.