public-activity/public_activity · error · PublicActivity::NoKeyProvided
No key provided for #{self.class.name}
Error message
No key provided for #{self.class.name} What it means
Error "No key provided for #{self.class.name}" thrown in public-activity/public_activity.
Source
Thrown at lib/public_activity/common.rb:292
end
# Prepares settings used during creation of Activity record.
# params passed directly to tracked model have priority over
# settings specified in tracked() method
#
# @see #create_activity
# @return [Hash] Settings with preserved options that were passed
# @api private
# @overload prepare_settings(action, options = {})
# @see #create_activity
# @overload prepare_settings(options = {})
# @see #create_activity
def prepare_settings(*args)
raw_options = args.extract_options!
action = [args.first, raw_options.delete(:action)].compact.first
key = prepare_key(action, raw_options)
raise NoKeyProvided, "No key provided for #{self.class.name}" unless key
prepare_custom_fields(raw_options.except(:params)).merge(
{
key: key,
owner: prepare_relation(:owner, raw_options),
recipient: prepare_relation(:recipient, raw_options),
parameters: prepare_parameters(raw_options),
}
)
end
# Prepares and resolves custom fields
# users can pass to `tracked` method
# @private
def prepare_custom_fields(options)
customs = self.class.activity_custom_fields_global.clone
customs.merge!(activity_custom_fields) if activity_custom_fields
customs.merge!(options)View on GitHub (pinned to 1f3a5568ad)
Solutions
- Pass an explicit key when calling create_activity: record.create_activity(key: 'article.create').
- Derive the key by passing an action symbol: record.create_activity(action: :create), so prepare_key builds '<model>.<action>'.
- Ensure the key/action option is not nil before tracking: check options[:key] and options[:action] in your tracked call.
Example fix
@article.create_activity(key: 'article.comment', owner: current_user, parameters: {comment: params[:comment]}) When it happens
Trigger: Raised by prepare_settings in lib/public_activity/common.rb:292 when no activity key can be resolved. Triggers when create_activity is called without an action argument and without an :action or :key option, and the model class was not declared with tracked(...) providing a default key. Common when the caller forgets to pass the action (e.g. article.create_activity with no arguments), or when the tracked block's key generation returned nil.
Common situations: See trigger scenarios.
AI-assisted analysis of public-activity/public_activity@1f3a5568ad (2026-08-23).
Data as JSON: /api/errors/1593515d582a252a.
Report an issue: GitHub.