{"record":{"id":"7f2222dcf7c88e62","repo":"ViewComponent/view_component","slug":"the-value-of-the-first-argument-passed-to-with-co","errorCode":null,"errorMessage":"The value of the first argument passed to `with_collection` isn't a valid collection. Make sure it responds to `to_ary`.","messagePattern":"The value of the first argument passed to `with_collection` isn't a valid collection\\. Make sure it responds to `to_ary`\\.","errorType":"exception","errorClass":"ViewComponent::InvalidCollectionArgumentError","httpStatus":null,"severity":"error","filePath":"lib/view_component/collection.rb","lineNumber":61,"sourceCode":"      @collection.map do |item|\n        component.new(**component_options(item, iterator)).tap do |_|\n          iterator.iterate!\n        end\n      end\n    end\n\n    def initialize(component, object, spacer_component, **options)\n      @component = component\n      @collection = collection_variable(object || [])\n      @spacer_component = spacer_component\n      @options = options\n    end\n\n    def collection_variable(object)\n      if object.respond_to?(:to_ary)\n        object.to_ary\n      else\n        raise InvalidCollectionArgumentError\n      end\n    end\n\n    def component_options(item, iterator)\n      item_options = @options.dup\n      item_options[component.__vc_collection_parameter] = item\n      item_options[component.__vc_collection_counter_parameter] = iterator.index if component.__vc_counter_argument_present?\n      item_options[component.__vc_collection_iteration_parameter] = iterator.dup if component.__vc_iteration_argument_present?\n\n      item_options\n    end\n\n    # Render the spacer through a fresh `dup` so a collection rendered multiple\n    # times always gets a clean spacer instance.\n    def rendered_spacer(view_context)\n      return \"\" unless @spacer_component\n\n      @spacer_component.dup.render_in(view_context)","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/ViewComponent/view_component/blob/9f22c36fa7d7b44098a8ed97472e3b4674ae420f/lib/view_component/collection.rb#L43-L79","documentation":"Error \"The value of the first argument passed to `with_collection` isn't a valid collection. Make sure it responds to `to_ary`.\" thrown in ViewComponent/view_component.","triggerScenarios":"Thrown at lib/view_component/collection.rb:61 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass an object that responds to `to_ary` (e.g. an Array or ActiveRecord::Relation) as the first argument to `with_collection`.","If the object is a single item, wrap it: with_collection([item]). If it is a custom enumerable, define `to_ary` or convert it with `.to_a`."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9f22c36fa7d7b44098a8ed97472e3b4674ae420f","analyzedAt":"2026-08-23T10:20:47.008Z","schemaVersion":2},"datasetVersion":"2026-08-23T13:39:53.451Z"}