0

I am using Pundit to authorize a model in my controller:

@board = authorize Board.find(id)

However, I have a full() method on my model that calls a mongodb aggregation and returns json. If I try to authorize that I get the error:

unable to find policy 'HashPolicy' for ... (object)

This is because Pundit expects an active_record model to authorize.

I am currently getting around this my first authorizing the Board.find(id), and then making a second db call to get the aggregation. This is obviously impractical.

Is there any way I can get Pundit to accept the json object? Or is there a way for me to get the original object back from my aggregation?

I_A
  • 331
  • 2
  • 14

1 Answers1

0

It turns out you have to explicitly set the policy_class if the record is not an active record object:

@board = authorize Board.find(id), policy_class: BoardPolicy

I_A
  • 331
  • 2
  • 14