Use array subtraction to compute variables of interest in view_assigns

上级 f6bf1705
......@@ -56,21 +56,17 @@ def rendered_format
Mime[:text]
end
DEFAULT_PROTECTED_INSTANCE_VARIABLES = Set.new %i(
@_action_name @_response_body @_formats @_prefixes
)
DEFAULT_PROTECTED_INSTANCE_VARIABLES = %i(@_action_name @_response_body @_formats @_prefixes)
# This method should return a hash with assigns.
# You can overwrite this configuration per controller.
def view_assigns
protected_vars = _protected_ivars
variables = instance_variables - _protected_ivars
instance_variables.each_with_object({}) do |name, hash|
unless protected_vars.include?(name)
variables.each_with_object({}) do |name, hash|
hash[name.slice(1, name.length)] = instance_variable_get(name)
end
end
end
private
# Normalize args by converting <tt>render "foo"</tt> to
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册