mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Only cache the view_context_class in one place
This patch removes the instance writer of view_context_class. Subclasses may override it, but it doesn't need to be written. This also eliminates the need to cache the return value of the class level `view_context_class` method.
This commit is contained in:
parent
63d96adb68
commit
8611b15924
2 changed files with 9 additions and 4 deletions
|
@ -160,9 +160,16 @@ module ActionDispatch
|
||||||
@controller.singleton_class.include(_routes.url_helpers)
|
@controller.singleton_class.include(_routes.url_helpers)
|
||||||
|
|
||||||
if @controller.respond_to? :view_context_class
|
if @controller.respond_to? :view_context_class
|
||||||
@controller.view_context_class = Class.new(@controller.view_context_class) do
|
view_context_class = Class.new(@controller.view_context_class) do
|
||||||
include _routes.url_helpers
|
include _routes.url_helpers
|
||||||
end
|
end
|
||||||
|
|
||||||
|
custom_view_context = Module.new {
|
||||||
|
define_method(:view_context_class) do
|
||||||
|
view_context_class
|
||||||
|
end
|
||||||
|
}
|
||||||
|
@controller.extend(custom_view_context)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
yield @routes
|
yield @routes
|
||||||
|
|
|
@ -55,10 +55,8 @@ module ActionView
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_internal_writer :view_context_class
|
|
||||||
|
|
||||||
def view_context_class
|
def view_context_class
|
||||||
@_view_context_class ||= self.class.view_context_class
|
self.class.view_context_class
|
||||||
end
|
end
|
||||||
|
|
||||||
# An instance of a view class. The default view class is ActionView::Base.
|
# An instance of a view class. The default view class is ActionView::Base.
|
||||||
|
|
Loading…
Reference in a new issue