-
-
Notifications
You must be signed in to change notification settings - Fork 810
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
Getting unexpected coercion within scopes. #566
Comments
I have the same problem currently here. Where i expect value such as 1 or true to be passed as string to my scope, they are converted to a boolean true. Even if they are enclosed in an array. |
While looking further in to this I discovered that the way you check for scope arity doesn't work in rails 4. If you look how scopes are implemented currently: https://github.com/rails/rails/blob/b1879124a82b34168412ac699cf6f654e005c4d6/activerecord/lib/active_record/scoping/named.rb#L154 you see that is defines a method, where the block passed is the scope method from rails which executes our own specified proc. So when you ask arity for the scope, you are actually asking for arity of the scope block from rails, which is always -1. |
@MarcelEeken thanks for looking into this. I use ransackers as they were the original implementation by Ernie for doing this. Scopes in Ransack were added much later by the community but never quite finished/polished. The early users of Ransack probably mostly stayed with their ransackers, but I wouldn't be surprised if many newer users are using scopes. So, tests and PRs for using scopes are very welcome 😃 |
I believe that yes, this issue has been discussed in depth at least once before. Do have a look, and don't hesitate to link this issue to the previous discussion. |
I started looking into it, but haven't found a solution yet. I have a red test case, but have not been able to think of a solution that doesn't clash with the way of conditionally adding a scope with a true or false value. One of the problems I think is, there is no way of determining if a scope needs arguments or not because of the wrapper rails adds to it with the current setup. |
Could you make a PR with the test case ? (commented out, and headed by a TODO comment) |
I will do that. |
Thanks! |
- Small typo fix (@MarcelEeken). - Update the TODO comment (@jonatack). These tests are related to issue #566. Closes PR #575.
Also related to #509. See my comments, I would like to standardize on Array = passed params (unconverted), and single value = use the scope if truthy. If that makes sense I will implement the fix. |
Closed by #566 |
I know that it is a discussed issue but I'm still getting errors.
Example:
ruby 2.2.2
rails 4.2.1
ransack 1.6.6
I want to catch 1 or '1' as param. Any idea?
The text was updated successfully, but these errors were encountered: