ViewComponent/view_component · error · ViewComponent::MissingCollectionArgumentError
The initializer for COMPONENT doesn't accept the parameter `
Error message
The initializer for COMPONENT doesn't accept the parameter `PARAMETER`, which is required to render it as a collection. To fix this issue, update the initializer to accept `PARAMETER`. See [the collections docs](https://viewcomponent.org/guide/collections.html) for more information on rendering collections.
What it means
Error "The initializer for COMPONENT doesn't accept the parameter `PARAMETER`, which is required to render it as a collection. To fix this issue, update the initializer to accept `PARAMETER`. See [the collections docs](https://viewcomponent.org/guide/collections.html) for more information on rendering collections." thrown in ViewComponent/view_component.
Source
Thrown at lib/view_component/base.rb:739
#
# @return [Boolean]
def strip_trailing_whitespace?
__vc_strip_trailing_whitespace
end
# Ensure the component initializer accepts the
# collection parameter. By default, we don't
# validate that the default parameter name
# is accepted, as support for collection
# rendering is optional.
# @private
def __vc_validate_collection_parameter!(validate_default: false)
parameter = validate_default ? __vc_collection_parameter : __vc_provided_collection_parameter
return unless parameter
return if __vc_initialize_parameter_names.include?(parameter) || __vc_splatted_keyword_argument_present?
raise MissingCollectionArgumentError.new(name, parameter)
end
# Ensure the component initializer doesn't define
# invalid parameters that could override the framework's
# methods.
# @private
def __vc_validate_initialization_parameters!
return unless __vc_initialize_parameter_names.include?(:content)
raise ReservedParameterError.new(name, :content)
end
# @private
def __vc_collection_parameter
@__vc_provided_collection_parameter ||= name && name.demodulize.underscore.chomp("_component").to_sym
end
# @privateView on GitHub (pinned to 9f22c36fa7)
Solutions
- Add the missing parameter to the component's initializer, e.g. def initialize(parameter:) - the parameter name is the singular name derived from the collection variable.
- If the collection item should use a different name, set `with_collection_parameter :custom_name` in the component and use that name in the initializer.
When it happens
Trigger: Thrown at lib/view_component/base.rb:739 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of ViewComponent/view_component@9f22c36fa7 (2026-08-23).
Data as JSON: /api/errors/1978421e1b81fa07.
Report an issue: GitHub.