Pundit: NoMethodError (undefined method `verify_authorized’ for [WhateversController])


Sometimes, having done things several times before can make you miss the OBVIOUS.

After adding

  after_action :verify_authorized

to my ApplicationController to verify that Pundit was being used for authorization, I got the following error in rspec:

  2) Jobs GET /jobs works! (now write some real specs)
     Failure/Error: get jobs_path
     NoMethodError:
       undefined method `verify_authorized' for #
     # ./spec/requests/jobs_spec.rb:6:in `block (3 levels) in '

Maybe there’s a problem with my RSpec? Nope:

Started GET "/" for 127.0.0.1 at 2015-07-31 07:13:17 -0500
Processing by JobsController#index as HTML
  Job Load (0.1ms)  SELECT "jobs".* FROM "jobs"
  Rendered jobs/index.html.slim within layouts/application (0.5ms)
Completed 500 Internal Server Error in 8ms

NoMethodError (undefined method `verify_authorized' for #):

Okay, does ApplicationController have the method?!

irb(main):008:0> ApplicationController.new.methods.include? :verify_authorized
=> false

Ok, am I doing that wrong?

irb(main):010:0> ApplicationController.new.methods.include? :authenticate_user!
=> true

Sigh. *Rereads documentation.*

Screenshot 2015-07-31 07.25.24

What’s missing? Oh yeah, a simple `include Pundit’ in the ApplicationController
8729962194_b4cc81b2ee_z


%d bloggers like this: