diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2019-01-23 15:44:32 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2019-02-06 16:57:00 -0800 |
commit | 5b4df9d0eb295d402489465f3600576038f5762d (patch) | |
tree | b3272f83a9833494e327b057fc38073202f722b0 /actionview | |
parent | f9bea6304dfba902b1937b3bc29b1ebc2f67e55b (diff) | |
download | rails-5b4df9d0eb295d402489465f3600576038f5762d.tar.gz rails-5b4df9d0eb295d402489465f3600576038f5762d.tar.bz2 rails-5b4df9d0eb295d402489465f3600576038f5762d.zip |
Regenerate AV::Base subclass when DetailsKey gets cleared
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/lib/action_view/base.rb | 7 | ||||
-rw-r--r-- | actionview/lib/action_view/rendering.rb | 25 |
2 files changed, 29 insertions, 3 deletions
diff --git a/actionview/lib/action_view/base.rb b/actionview/lib/action_view/base.rb index 1e58004fcf..c5d8cdd409 100644 --- a/actionview/lib/action_view/base.rb +++ b/actionview/lib/action_view/base.rb @@ -185,9 +185,14 @@ module ActionView #:nodoc: template_container = Module.new Class.new(self) { include template_container - define_method(:compiled_method_container) { template_container } + define_method(:compiled_method_container) { template_container } + define_singleton_method(:compiled_method_container) { template_container } } end + + def changed?(other) # :nodoc: + compiled_method_container != other.compiled_method_container + end end attr_reader :view_renderer diff --git a/actionview/lib/action_view/rendering.rb b/actionview/lib/action_view/rendering.rb index 01caa82ec6..8246e4ba6d 100644 --- a/actionview/lib/action_view/rendering.rb +++ b/actionview/lib/action_view/rendering.rb @@ -35,14 +35,35 @@ module ActionView end module ClassMethods + def _routes + end + + def _helpers + end + + def build_av_class(klass, supports_path, routes, helpers) + Class.new(klass) do + if routes + include routes.url_helpers(supports_path) + include routes.mounted_helpers + end + + if helpers + include helpers + end + end + end + def view_context_class klass = ActionView::LookupContext::DetailsKey.view_context_class(ActionView::Base) - @view_context_class ||= build_view_context_class(klass, supports_path?, _routes, _helpers) + @view_context_class ||= build_av_class(klass, supports_path?, _routes, _helpers) if klass.changed?(@view_context_class) - @view_context_class = build_view_context_class(klass, supports_path?, _routes, _helpers) + @view_context_class = build_av_class(klass, supports_path?, _routes, _helpers) end + + @view_context_class end end |