CanCanCommunity/cancancan · error · CanCan::NotImplemented
This model adapter does not support matching on a specific c
Error message
This model adapter does not support matching on a specific condition.
What it means
AbstractAdapter#matches_condition? (lib/cancan/model_adapters/abstract_adapter.rb:63) raises CanCan::NotImplemented. It is only called when the adapter's override_condition_matching?(subject, name, value) returns true — the per-condition override hook — so this error means an adapter promised per-condition matching for some (subject, attribute) pair but never implemented the method.
Source
Thrown at lib/cancan/model_adapters/abstract_adapter.rb:63
# If this returns true then nested_subject_matches_conditions? will be called.
def self.override_nested_subject_conditions_matching?(_parent, _child, _all_conditions)
false
end
# Override if override_nested_subject_conditions_matching? returns true
def self.nested_subject_matches_conditions?(_parent, _child, _all_conditions)
raise NotImplemented, 'This model adapter does not support matching on a nested subject.'
end
# Used to determine if this model adapter will override the matching behavior for a specific condition.
# If this returns true then matches_condition? will be called. See Rule#matches_conditions_hash
def self.override_condition_matching?(_subject, _name, _value)
false
end
# Override if override_condition_matching? returns true
def self.matches_condition?(_subject, _name, _value)
raise NotImplemented, 'This model adapter does not support matching on a specific condition.'
end
def initialize(model_class, rules)
@model_class = model_class
@rules = rules
end
def database_records
# This should be overridden in a subclass to return records which match @rules
raise NotImplemented, 'This model adapter does not support fetching records from the database.'
end
end
end
end
View on GitHub (pinned to 8c1bf153a3)
Solutions
- Implement self.matches_condition?(subject, name, value) for every (name, value) shape your override_condition_matching? claims.
- Or narrow override_condition_matching? so it returns true only for the cases you actually handle, letting others fall through to default matching.
- If using a third-party adapter: upgrade it or replace the exotic condition with a plain attribute/block condition.
Example fix
# before (custom adapter) def self.override_condition_matching?(_subject, name, _value) true # claims every condition, implements none end # after def self.override_condition_matching?(_subject, name, _value) false # default matching handles regular columns end # and only flip to true for specific names you implement in # def self.matches_condition?(subject, name, value); ...; end
Defensive patterns
Strategy: validation
Validate before calling
# adapter authors: scope the claim to conditions you really implement
class MyAdapter < CanCan::ModelAdapters::AbstractAdapter
HANDLED = %i[geometry].freeze
def self.override_condition_matching?(_subject, name, _value)
HANDLED.include?(name.to_sym) # false elsewhere -> default matching
end
end Type guard
def adapter_supports_condition?(adapter, subject, name, value) !adapter.override_condition_matching?(subject, name, value) || adapter.method(:matches_condition?).owner != CanCan::ModelAdapters::AbstractAdapter end
Try / catch
begin
can?(:read, @map)
rescue CanCan::NotImplemented => e
Rails.logger.error("adapter incomplete: #{e.message}")
false
end Prevention
- Never return true unconditionally from override_condition_matching?.
- Pair every override_condition_matching? branch with a spec for matches_condition?.
- Replace exotic conditions with plain attributes or blocks when the adapter cannot match them.
When it happens
Trigger: A custom adapter with special handling like def self.override_condition_matching?(subject, name, value); name == :geometry; end but no matches_condition? implementation; then a rule containing that condition (can :read, Map, geometry: polygon) is instance-checked via can?/authorize!.
Common situations: Adapters adding support for non-column condition types (arrays, JSON columns, geo types) and forgetting the matcher half of the pair; partial vendored forks of the ActiveRecord adapter.
Related errors
- This model adapter does not support matching on a conditions
- This model adapter does not support matching on a nested sub
- This model adapter does not support fetching records from th
- You are not authorized to access this page.
- You can't specify target (#{target}) as alias because it is
AI-assisted analysis of CanCanCommunity/cancancan@8c1bf153a3 (2026-08-21).
Data as JSON: /api/errors/d9a8852ced9e5588.
Report an issue: GitHub.