-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Updating documentation around ransack #3709
Updating documentation around ransack #3709
Conversation
This PR updates the documentation around customizing Ransack attributes to recommend the use of a decorator instead of an initializer. This allows the code to reload correctly when using Zeitwerk under Rails 6+. Addresses solidusio#3706
The test failure seems most likely to be a flake - is there a good way to re-run this via Circle? |
@tmtrademarked no worries, the failure on |
the `config/initializers/spree.rb` initializer: | ||
[ransack][ransack]. The easiest way to achieve this is by adding a decorator | ||
which will update the attributes. This ensures that the code is reloaded correctly | ||
when needed. (Using an initializer does not work with Rails 6+ and Zeitwerk) For this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about moving the sentence is the parentheses before the end of the sentence (dot)?
So that it would read like this:
when needed (using an initializer does not work with Rails 6+ and Zeitwerk). For...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing - updated!
module YourApp | ||
module Spree | ||
class OrderDecorator | ||
Spree::Order.whitelisted_ransackable_attributes << 'last_ip_address' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this version that actually leverages the prepend
instruction below?
class OrderDecorator
def self.prepended(base)
base.whitelisted_ransackable_attributes << 'last_ip_address'
end
end
It's a bit longer, but it avoids repeating the Spree::Order
class name inside the module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it - a bit cleaner to read. Updated!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tmtrademarked thank you 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot!
This PR updates the documentation around customizing Ransack attributes to recommend the use of a decorator instead of an initializer. This allows the code to reload correctly when using Zeitwerk under Rails 6+.
Addresses #3706
Checklist: