activerecord-hackery/ransack · error · ArgumentError
Invalid argument (#{args.class}) supplied to values=
Error message
Invalid argument (#{args.class}) supplied to values= What it means
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.
Source
Thrown at lib/ransack/nodes/condition.rb:116
def values
@values ||= []
end
alias :v :values
def values=(args)
case args
when Array
args.each do |val|
val = Value.new(@context, val)
self.values << val
end
when Hash
args.each do |index, attrs|
val = Value.new(@context, attrs[:value])
self.values << val
end
else
raise ArgumentError,
"Invalid argument (#{args.class}) supplied to values="
end
end
alias :v= :values=
def combinator
@attributes.size > 1 ? @combinator : nil
end
def combinator=(val)
@combinator = Constants::AND_OR.detect { |v| v == val.to_s } || nil
end
alias :m= :combinator=
alias :m :combinator
# == build_attribute
#
# This method was originally called from Nodes::Grouping#new_conditionView on GitHub (pinned to e82f6bab39)
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')
Example fix
# before condition.values = 'Alice' # => ArgumentError: Invalid argument (String) supplied to values= # after condition.values = ['Alice']
Defensive patterns
Strategy: validation
Validate before calling
vals = Array(vals) unless vals.is_a?(Hash) condition.values = vals
Type guard
def valid_values_arg?(arg) arg.is_a?(Array) || arg.is_a?(Hash) end
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid argument (#{args.class}) supplied to attributes=
- Invalid argument (#{groupings.class}) supplied to groupings=
- #{type} cannot be converted to an ARel join type
- #{value} cannot be converted to a Class
- Don't know what context to use for #{object}
AI-assisted analysis of activerecord-hackery/ransack@e82f6bab39 (2026-08-21).
Data as JSON: /api/errors/05d336e73e339291.
Report an issue: GitHub.