-
-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ransackable_scope with boolean value is skipped #1375
Comments
Problem runs down to if we can detect arity of scope or not. This question was asked before rails/rails#28198 First problem is that all scopes are wrapped by Rails https://github.com/rails/rails/blob/8015c2c2cf5c8718449677570f372ceb01318a32/activerecord/lib/active_record/scoping/named.rb#L173-L188 if body.respond_to?(:to_proc)
# arity = 1
singleton_class.define_method(name) do |*args|
scope = all._exec_scope(*args, &body)
scope = scope.extending(extension) if extension
scope
end
else
# arity = body.arity
singleton_class.define_method(name) do |*args|
scope = body.call(*args) || all
scope = scope.extending(extension) if extension
scope
end
end
singleton_class.send(:ruby2_keywords, name) So it means that what ever we do Side note (what
Second problem is that there are two ways to define scopes: with Proc and with Lambda. And arity behaves differently for them: |
For those looking for a workaround. I disabled the automatic type conversion of booleans with: Ransack.configure do |c|
c.sanitize_custom_scope_booleans = false
end This means the querystring param is a string of scope :active, ->(bool=true) {
# Maybe coming in as a string that is "true" or "false"
bool = ActiveModel::Type::Boolean.new.cast bool
....
} |
This issue was reported before, but I'm not sure how it is resolved #831
I pass hash directly to ransack I would expect that value would be passed to
activated
(boolean: false
)Possible solution:
Related https://stackoverflow.com/a/34390913/1190041
The text was updated successfully, but these errors were encountered: