{"record":{"id":"05d336e73e339291","repo":"activerecord-hackery/ransack","slug":"invalid-argument-args-class-supplied-to-value","errorCode":null,"errorMessage":"Invalid argument (#{args.class}) supplied to values=","messagePattern":"Invalid argument \\(#(.+?)\\) supplied to values=","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/ransack/nodes/condition.rb","lineNumber":116,"sourceCode":"      def values\n        @values ||= []\n      end\n      alias :v :values\n\n      def values=(args)\n        case args\n        when Array\n          args.each do |val|\n            val = Value.new(@context, val)\n            self.values << val\n          end\n        when Hash\n          args.each do |index, attrs|\n            val = Value.new(@context, attrs[:value])\n            self.values << val\n          end\n        else\n          raise ArgumentError,\n            \"Invalid argument (#{args.class}) supplied to values=\"\n        end\n      end\n      alias :v= :values=\n\n      def combinator\n        @attributes.size > 1 ? @combinator : nil\n      end\n\n      def combinator=(val)\n        @combinator = Constants::AND_OR.detect { |v| v == val.to_s } || nil\n      end\n      alias :m= :combinator=\n      alias :m :combinator\n\n      # == build_attribute\n      #\n      #  This method was originally called from Nodes::Grouping#new_condition","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/activerecord-hackery/ransack/blob/e82f6bab3956c5597e7debbefa218d9e94e58ceb/lib/ransack/nodes/condition.rb#L98-L134","documentation":"Nodes::Condition#values= (aliased v=) mirrors attributes=: it accepts only an Array of values or an indexed Hash ({'0' => {value: ...}, ...}). Passing a bare scalar (String, Integer, nil-set scalars outside the accepted shapes) raises this ArgumentError. Normal form params arrive as indexed hashes, so this almost always comes from programmatic condition building.","triggerScenarios":"condition.values = 'Alice' (String); condition.v = 42; building a condition manually with v: 'Alice' instead of v: ['Alice']; merging JSON payloads where the value index level is lost.","commonSituations":"Service objects/specs constructing Ransack nodes by hand; converting JSON search payloads to Ransack params and dropping the nested {index: {value: ...}} layer; copying examples that predate the current node API.","solutions":["Wrap the value in an array: condition.v = ['Alice']","Or use the indexed hash form: condition.values = { '0' => { value: 'Alice' } }","Better, let Search#build create the condition wholesale: Person.ransack(name_eq: 'Alice')"],"exampleFix":"# before\ncondition.values = 'Alice'\n# => ArgumentError: Invalid argument (String) supplied to values=\n\n# after\ncondition.values = ['Alice']","handlingStrategy":"validation","validationCode":"vals = Array(vals) unless vals.is_a?(Hash)\ncondition.values = vals","typeGuard":"def valid_values_arg?(arg)\n  arg.is_a?(Array) || arg.is_a?(Hash)\nend","tryCatchPattern":null,"preventionTips":["Wrap condition values in arrays: v: ['Alice'], not v: 'Alice'","Keep the indexed hash shape ({'0' => {value: x}}) when converting external payloads","Assert argument shapes in unit tests for custom condition-building code"],"tags":["ruby","rails","ransack","nodes","conditions","argumenterror"],"backgroundTag":"invalid-params-structure","analyzedSha":"e82f6bab3956c5597e7debbefa218d9e94e58ceb","analyzedAt":"2026-08-21T19:30:23.639Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}