draper
draper copied to clipboard
[Suggestion] - set Draper::ViewContext explicitly
Right now there are many issues due to Draper::ViewContext
inflexibility
I would like to suggest to explicitly set Draper::ViewContext, rather than rely on RequestStore
For example
# helper method definition
def draper_context
old_value = Draper::ViewContext.current
Draper::ViewContext.current = self
yield
ensure
Draper::ViewContext.current = old_value
end
# somewhere, e.g. in controller
draper_context do
decorated_posts = posts.decorate
end
Note: right now that won't work as decorated object does not remember context when it was created
Ultimately decorates_assigned
would be switch to this helper as well as every other use of draper, so that solution with RequestStore
could be deprecated and removed.
What do you think?