{"record":{"id":"db6cf8fdca62b60c","repo":"activerecord-hackery/ransack","slug":"invalid-argument-args-class-supplied-to-attri","errorCode":null,"errorMessage":"Invalid argument (#{args.class}) supplied to attributes=","messagePattern":"Invalid argument \\(#(.+?)\\) supplied to attributes=","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/ransack/nodes/condition.rb","lineNumber":92,"sourceCode":"      end\n\n      def attributes\n        @attributes ||= []\n      end\n      alias :a :attributes\n\n      def attributes=(args)\n        case args\n        when Array\n          args.each do |name|\n            build_attribute(name)\n          end\n        when Hash\n          args.each do |index, attrs|\n            build_attribute(attrs[:name], attrs[:ransacker_args])\n          end\n        else\n          raise ArgumentError,\n            \"Invalid argument (#{args.class}) supplied to attributes=\"\n        end\n      end\n      alias :a= :attributes=\n\n      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","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/activerecord-hackery/ransack/blob/e82f6bab3956c5597e7debbefa218d9e94e58ceb/lib/ransack/nodes/condition.rb#L74-L110","documentation":"Nodes::Condition#attributes= (aliased a=) accepts only an Array of attribute names or a Rails-style Hash of indexed attribute descriptors ({'0' => {name: ..., ransacker_args: ...}}). Any other class — a bare String like 'name_cont', a Symbol, or a scalar — raises this ArgumentError. It is reached when building conditions programmatically or from hand-shaped params.","triggerScenarios":"condition.attributes = 'name_eq' (String); condition.a = :name (Symbol); search.build(c: { a: 'name_eq' }) producing a string on a=; manually invoking Condition#build with a: 'body_cont' instead of a: ['body_cont'].","commonSituations":"Hand-building condition nodes in service objects or specs and forgetting the array wrapper; feeding partially-stringified params (q[c][a]=name_eq) that skip the Rails nested-hash indexing into a strict build path.","solutions":["Wrap single attribute names in an array: condition.a = ['name_eq']","When building via params, use the indexed hash form Rails produces: q = { c: { '0' => { a: ['name_eq'], v: ['Alice'] } } }","Prefer the top-level attribute_key API (Person.ransack(name_eq: 'Alice')) which handles wrapping for you"],"exampleFix":"# before\ncondition = search.build_condition\ncondition.attributes = 'name_eq'\n# => ArgumentError: Invalid argument (String) supplied to attributes=\n\n# after\ncondition.attributes = ['name_eq']","handlingStrategy":"validation","validationCode":"attrs = Array(attrs) unless attrs.is_a?(Hash)\ncondition.attributes = attrs  # Array or indexed Hash pass, everything else is rejected","typeGuard":"def valid_attributes_arg?(arg)\n  arg.is_a?(Array) || arg.is_a?(Hash)\nend","tryCatchPattern":null,"preventionTips":["Always wrap attribute names in arrays when setting condition.a= programmatically","Prefer Model.ransack(attr_pred => value) over hand-assembled nodes","When importing params from JSON, normalize to the indexed {'0' => {...}} shape Rails produces"],"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"}