-
Notifications
You must be signed in to change notification settings - Fork 527
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
Draper::QueryMethods does not preserve context #864
Comments
I would imagine that the context should be passed along anytime |
Discovered a workaround until this is fixed which is to use a similar approach to adding Pagination support. In the application specific collection decorator class, you can add the class ApplicationDecorator < Draper::Decorator
def self.collection_decorator_class
PaginatingDecorator
end
end
class PaginatingDecorator < Draper::CollectionDecorator
# support for will_paginate
delegate :current_page, :total_entries, :total_pages, :per_page, :offset
def order(*args)
collection = super
collection.context = self.context
collection
end
def paginate(*args)
object.paginate(*args).decorate(context: self.context)
end
end |
Fixed by: #868 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Given: Creation of a Decorator::Collection instance with a context and calling
order
on that collection to pass database sort ordering through to the ActiveRecord::AssociationExpected: The resulting collection should preserve the original context
Actual: It does not preserve the context.
Example code:
I don't know if this is the proper long term fix for this, but this fix works in Draper::QueryMethods:
draper/lib/draper/query_methods.rb
Lines 6 to 10 in dd32a4a
to:
The text was updated successfully, but these errors were encountered: