aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/abstract_controller/rendering.rb
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-03-18 18:12:04 -0700
committerCarlhuda <carlhuda@engineyard.com>2010-03-18 18:14:54 -0700
commita5d80f84d269bba6b0f0802612f29df1ee09d720 (patch)
treed5673cda114eeaab9dcbc7107d227f6c83f2c2f3 /actionpack/lib/abstract_controller/rendering.rb
parente629e21135d9d0e87c02e1106e489f943f19d2d9 (diff)
downloadrails-a5d80f84d269bba6b0f0802612f29df1ee09d720.tar.gz
rails-a5d80f84d269bba6b0f0802612f29df1ee09d720.tar.bz2
rails-a5d80f84d269bba6b0f0802612f29df1ee09d720.zip
Each controller class has it's own view context subclass. This removes the need for ActionView::Base.for_controller
Diffstat (limited to 'actionpack/lib/abstract_controller/rendering.rb')
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb28
1 files changed, 24 insertions, 4 deletions
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb
index 402ad7c8d7..58d339d563 100644
--- a/actionpack/lib/abstract_controller/rendering.rb
+++ b/actionpack/lib/abstract_controller/rendering.rb
@@ -42,18 +42,38 @@ module AbstractController
I18n.config = old_config
end
+ module ClassMethods
+ def view_context_class
+ @view_context_class ||= begin
+ controller = self
+ Class.new(ActionView::Base) do
+ if controller.respond_to?(:_helpers)
+ include controller._helpers
+ # TODO: Fix RJS to not require this
+ self.helpers = controller._helpers
+ end
+ end
+ end
+ end
+ end
+
+ attr_writer :view_context_class
+
+ def view_context_class
+ @view_context_class || self.class.view_context_class
+ end
+
# An instance of a view class. The default view class is ActionView::Base
#
# The view class must have the following methods:
- # View.for_controller[controller]
+ # View.new[lookup_context, assigns, controller]
# Create a new ActionView instance for a controller
- # View#render_template[options]
+ # View#render[options]
# Returns String with the rendered template
#
# Override this method in a module to change the default behavior.
def view_context
- klass = ActionView::Base.for_controller(self)
- klass.new(lookup_context, view_assigns, self)
+ view_context_class.new(lookup_context, view_assigns, self)
end
# Normalize arguments, options and then delegates render_to_body and