Date predicate is formatted as string
Hello,
in previous versions, block in this code use to receive a time object:
Ransack.configure do |config|
config.add_predicate 'lteq_eod',
arel_predicate: 'lteq',
formatter: proc { |value| value.end_of_day },
type: :date
end
After upgrading from 4.3.0 to 4.4.0, the proc block started receiving an string.
@dcrec1 are you able to test this PR ? https://github.com/activerecord-hackery/ransack/pull/1651
Hi @scarroll32, @dcrec1
I’m also encountering the same error. I believe the cause is that it no longer casts the value when it’s not an array. This change was introduced in PR #1559. I’ve confirmed that the issue can be avoided with the following monkey patch:
Ransack::Nodes::Condition.prepend(
Module.new do
def casted_values_for_attribute(attr)
validated_values.map { |v| v.cast_array(predicate.type || attr.type) }
end
end
)
Ransack::Nodes::Value.prepend(
Module.new do
def cast_array(type)
if value.is_a?(Array)
cast_to_date(value)
else
cast(type)
end
end
end
)
PR #1559 was reverted in v4.4.1 via PR #1645. So, I believe this issue was resolved in v4.4.1.