Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method 'authorize' with Pundit

I've installed the gem Pundit in my Rails app, and have followed the instructions in the README carefully.

However, when I use authorize in any of my controllers, I get the error message "undefined method 'authorize' for .

Also, when I try to use "policy" in a view, I get the error "undefined method 'policy'".

It's as if Pundit weren't installed at all!

I've included Pundit in my Application Controller.

I have an ApplicationPolicy file with all of my policies, then policy files for each type of record that inherit from the Application Policy.

For some reason, I can't paste any of my code into this question, so I'm hoping I've included enough information!

I'd appreciate any thoughts.

like image 623
Ellen W Avatar asked Oct 20 '22 21:10

Ellen W


1 Answers

I have recently used pundit and it worked like a charm. your error messages makes me infer that you've not run install rails g pundit:install or your policies file are not in correct directories.

or if they are then Just restarting the server should fix this. Hopefully.

like image 164
Neeraj Gupta Avatar answered Oct 27 '22 01:10

Neeraj Gupta