rails/rails — Issue #4906: Why is `view_context` not cached?
Author: haihappen
Created: 2012-02-06 12:12:57+00:00
State: open

Is there any good reason why `view_context` is not being cached?

```ruby

# An instance of a view class. The default view class is ActionView::Base
#
# The view class must have the following methods:
# View.new[lookup_context, assigns, controller]
# Create a new ActionView instance for a controller
# View#render[options]
# Returns String with the rendered template
#
# Override this method in a module to change the default behavior.
def view_context
view_context_class.new(view_renderer, view_assigns, self)
end
```

A lot of 3rd party gems rely on `view_context`, for example [draper](https://github.com/jcasimir/draper). Because `view_context` always returns a new object, there are some weird and really hard to debug errors, when using Rails helper which depend on instance variables. A good example is `content_for` which will not work if used in and outside of Draper `Decorator` classes.