Closed helphop closed 6 years ago
lib/null_object.rb
require 'naught' NulllObject = Naught.build do |config| config.define_explicit_conversions config.define_implicit_conversions config.black_hole end
In my model:
def self.find_by_id(id) ProofreadingJob.where(id: id).first || NullObject.new end
I have the following in my controller:
def show @proofreading_job = ProofreadingJob.find_by_id(params[:id]) authorize [:proofreader, @proofreading_job], :show? end
Pundit gives the following error:
unable to find policyProofreader::Policyfor[:proofreader, null]`
unable to find policy
for
However, if I create a simple NullObject class as follows:
class NullObject end
And don't use the one built using the Naught gem, Pundit can read the class of this NullObject and can find the NullObjectPolicy.
Even more bizarre is if I do the following:
def show @proofreading_job = ProofreadingJob.find_by_id(params[:id]) authorize [:proofreader, @proofreading_job.class], :show? end
It works. Any ideas why Pundit can't 'see' the class of the NullObject derived from the Naught gem?
lib/null_object.rb
In my model:
I have the following in my controller:
Pundit gives the following error:
unable to find policy
Proofreader::Policyfor
[:proofreader, null]`However, if I create a simple NullObject class as follows:
class NullObject end
And don't use the one built using the Naught gem, Pundit can read the class of this NullObject and can find the NullObjectPolicy.
Even more bizarre is if I do the following:
It works. Any ideas why Pundit can't 'see' the class of the NullObject derived from the Naught gem?