Search code examples
ruby-on-railsstipundit

STI and PUNDIT - unable to find policy


I have three models:

class Post < ApplicationRecord
class Diary < Post
class FuturePlans < Post

I have also included the pundit in posts_controller.rb:

class BlogsController < ApplicationController
 include Pundit

And I have a post_policy.rb:

class BlogPolicy < ApplicationPolicy

class Scope < Scope
 def resolve
  return scope.all
 end
end

I seeded some diaries and futureplans with bankseed, included pundit in all the actions inside the controller, and I get the following error:

unable to find policy "DiaryPolicy" for "#<Diary id:...

Should I make separate policies for Diary and FuturePlans? How do I make them inherit pundit as well? When I disable pundit it all works.

Thanks!


Solution

  • I created DiaryPolicy and FuturePlansPolicy and it works again.