You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Passing a Time value to a scope leads to unexpected behavior. The Time value
appears to be passed as *time_value#to_a. This causes an error as the scope
expects a single Time object and not the 10 elements returned by Time#to_a.
The value should be passed simply as the time object (e.g., time_value).
I've created a failing spec and pasted the error output (since the scope expects a single value) below.
I haven't yet looked into writing a fix for this issue. If there's interest I'm happy to do so and submit a PR.
1) Ransack::Adapters::ActiveRecord::Base#search with scopes passes Time values to scopes
Failure/Error: search = Person.ransack('over_age' => time)
ArgumentError:
wrong number of arguments (10 for 1)
# ./spec/support/schema.rb:41:in `block in <class:Person>'
# ~/.rbenv/.../active_record/scoping/named.rb:155:in `call'
# ~/.rbenv/.../active_record/scoping/named.rb:155:in `block (2 levels) in scope'
# ~/.rbenv/.../active_record/relation.rb:302:in `scoping'
# ~/.rbenv/.../active_record/scoping/named.rb:155:in `block in scope'
# ~/.rbenv/.../active_record/relation/delegation.rb:70:in `block in over_age'
# ~/.rbenv/.../active_record/relation.rb:302:in `scoping'
# ~/.rbenv/.../active_record/relation/delegation.rb:70:in `over_age'
# ./lib/ransack/context.rb:56:in `public_send'
# ./lib/ransack/context.rb:56:in `chain_scope'
# ./lib/ransack/search.rb:138:in `add_scope'
# ./lib/ransack/search.rb:53:in `block in build'
# ./lib/ransack/search.rb:47:in `each'
# ./lib/ransack/search.rb:47:in `build'
# ./lib/ransack/search.rb:39:in `initialize'
# ./lib/ransack/adapters/active_record/base.rb:15:in `new'
# ./lib/ransack/adapters/active_record/base.rb:15:in `ransack'
# ./spec/ransack/adapters/active_record/base_spec.rb:68:in `block (4 levels) in <module:ActiveRecord>'
P.S. Thanks for a great gem!
The text was updated successfully, but these errors were encountered:
The README might be referring to this when it says: "scopes with an array as an argument are not easily usable yet, because the array currently needs to be wrapped in an array to function (see #404), which is not compatible with Ransack form helpers. For this use case, it may be better for now to use ransackers instead, where feasible. Pull requests with solutions and tests are welcome!"
What versions of Rails, Ruby and Ransack are you using?
Passing a Time value to a scope leads to unexpected behavior. The Time value
appears to be passed as
*time_value#to_a
. This causes an error as the scopeexpects a single Time object and not the 10 elements returned by
Time#to_a
.The value should be passed simply as the time object (e.g.,
time_value
).I've created a failing spec and pasted the error output (since the scope expects a single value) below.
I haven't yet looked into writing a fix for this issue. If there's interest I'm happy to do so and submit a PR.
P.S. Thanks for a great gem!
The text was updated successfully, but these errors were encountered: