feat(ransack_allow_*): ransackable_* class method definition helpers #1546
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add helper methods for defining Ransack-allowed elements:
ransack_allow_attributes :column_a, :column_b
ransack_allow_associations :association_a, :association_b
ransack_allow_scopes :scope_a, :scope_b
These helpers provide a more convenient and cleaner way to define the ransackable_* class methods.
They use define_singleton_method internally, maintaining full compatibility with Ransack's existing functionality.
In a project, I implemented these methods on its ApplicationRecord class.
To me, it feels more readable when I define the allowed_attributes, allowed_associations and allowed_scopes in this way.
Ransack's codebase would not require any further changes for this, since it simply uses define_singleton_method to define the methods I would otherwise have created.
I reckon introducing these would require proper documentation.
No worries - I'm happy to help with that and do as much of the groundwork as I can.
However, first I want to find out if the maintainers think this idea has merit at all.
This PR is more of a trial balloon to gauge what the Ransack maintainers think of these methods.