0

I am building a rails API and I'm using pundit for authorizations to the API. I am trying to define current_user for pundit with this method:

def pundit_user
  User.find_by_other_means
end

I tried implementing it as a private method in my API base controller but it gives me this error:

"exception": "#<NoMethodError: undefined method `find_by_other_means' for #<Class:0x00007f9d25463768>\nDid you mean?  find_or_create_by>"

Then I tried implementing it on my application controller and it gives me the following error:

"exception": "#<NameError: undefined local variable or method `current_user' for #<Api::V1::NewsController:0x00007f9d2516b038>>"

How can I define current_user in pundit?

problems
  • 95
  • 1
  • 8
  • When defining `pundit_user` you have to write your own code for returning your user class - `find_by_other_means` mentioned in the documentation is just a placeholder. – eugen Oct 20 '20 at 14:34

1 Answers1

0

You can define your own current_user in ApplicationController, or use pundit_user - as mentioned in the documentation

eugen
  • 8,916
  • 11
  • 57
  • 65