Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move protected_instance_variables & view_assigns to AbstractController

  • Loading branch information...
commit 49608f7b81314fea0487311f57b41b721c375339 1 parent 3419ac2
Łukasz Strzałkowski strzalek authored
21 actionpack/lib/abstract_controller/rendering.rb
View
@@ -1,3 +1,6 @@
+require 'active_support/concern'
+require 'active_support/core_ext/class/attribute'
+
module AbstractController
class DoubleRenderError < Error
DEFAULT_MESSAGE = "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like \"redirect_to(...) and return\"."
@@ -8,6 +11,17 @@ def initialize(message = nil)
end
module Rendering
+ extend ActiveSupport::Concern
+
+ included do
+ class_attribute :protected_instance_variables
+ self.protected_instance_variables = []
+ end
+
+ def default_protected_instance_vars
+ [:@_action_name, :@_response_body, :@_formats, :@_prefixes, :@_config]
+ end
+
# Raw rendering of a template to a string.
#
# It is similar to render, except that it does not
@@ -34,7 +48,12 @@ def render(*args, &block)
# You can overwrite this configuration per controller.
# :api: public
def view_assigns
- {}
+ hash = {}
+ variables = instance_variables
+ variables -= protected_instance_variables
+ variables -= default_protected_instance_vars
+ variables.each { |name| hash[name[1..-1]] = instance_variable_get(name) }
+ hash
end
# Normalize args by converting render "foo" to render :action => "foo" and
19 actionview/lib/action_view/rendering.rb
View
@@ -23,11 +23,6 @@ module Rendering
extend ActiveSupport::Concern
include ActionView::ViewPaths
- included do
- class_attribute :protected_instance_variables
- self.protected_instance_variables = []
- end
-
# Overwrite process to setup I18n proxy.
def process(*) #:nodoc:
old_config, I18n.config = I18n.config, I18nProxy.new(I18n.config, lookup_context)
@@ -106,21 +101,15 @@ def _render_template(options) #:nodoc:
view_renderer.render(view_context, options)
end
- DEFAULT_PROTECTED_INSTANCE_VARIABLES = [
- :@_action_name, :@_response_body, :@_formats, :@_prefixes, :@_config,
- :@_view_context_class, :@_view_renderer, :@_lookup_context
- ]
+ def default_protected_instance_vars
+ super + [:@_view_context_class, :@_view_renderer, :@_lookup_context]
+ end
# This method should return a hash with assigns.
# You can overwrite this configuration per controller.
# :api: public
def view_assigns
- hash = super
- variables = instance_variables
- variables -= protected_instance_variables
- variables -= DEFAULT_PROTECTED_INSTANCE_VARIABLES
- variables.each { |name| hash[name[1..-1]] = instance_variable_get(name) }
- hash
+ super
end
private
Please sign in to comment.
Something went wrong with that request. Please try again.