aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib')
-rwxr-xr-xactionpack/lib/action_controller/base.rb25
-rw-r--r--actionpack/lib/action_view/base.rb22
2 files changed, 43 insertions, 4 deletions
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 5249fd035a..9b77f0fb55 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -430,7 +430,7 @@ module ActionController #:nodoc:
# Adds a view_path to the front of the view_paths array.
# If the current class has no view paths, copy them from
- # the superclass
+ # the superclass. This change will be visible for all future requests.
#
# ArticleController.prepend_view_path("views/default")
# ArticleController.prepend_view_path(["views/default", "views/custom"])
@@ -442,7 +442,7 @@ module ActionController #:nodoc:
# Adds a view_path to the end of the view_paths array.
# If the current class has no view paths, copy them from
- # the superclass
+ # the superclass. This change will be visible for all future requests.
#
# ArticleController.append_view_path("views/default")
# ArticleController.append_view_path(["views/default", "views/custom"])
@@ -636,7 +636,6 @@ module ActionController #:nodoc:
request.session_options && request.session_options[:disabled] != false
end
-
self.view_paths = []
# View load paths for controller.
@@ -647,7 +646,27 @@ module ActionController #:nodoc:
def view_paths=(value)
(@template || self.class).view_paths = value
end
+
+ # Adds a view_path to the front of the view_paths array.
+ # This change affects the current request only.
+ #
+ # self.prepend_view_path("views/default")
+ # self.prepend_view_path(["views/default", "views/custom"])
+ #
+ def prepend_view_path(path)
+ (@template || self.class).prepend_view_path(path)
+ end
+ # Adds a view_path to the end of the view_paths array.
+ # This change affects the current request only.
+ #
+ # self.append_view_path("views/default")
+ # self.append_view_path(["views/default", "views/custom"])
+ #
+ def append_view_path(path)
+ (@template || self.class).append_view_path(path)
+ end
+
protected
# Renders the content that will be returned to the browser as the response body.
#
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index 9901f81d56..a12574a09f 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -265,7 +265,7 @@ module ActionView #:nodoc:
end
def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil)#:nodoc:
- @view_paths = view_paths.respond_to?(:find) ? view_paths : [*view_paths].compact
+ @view_paths = view_paths.respond_to?(:find) ? view_paths.dup : [*view_paths].compact
@assigns = assigns_for_first_render
@assigns_added = nil
@controller = controller
@@ -472,6 +472,26 @@ If you are rendering a subtemplate, you must now use controller-like partial syn
TEMPLATE_HANDLER_PREFERENCES[template_format] || DEFAULT_TEMPLATE_HANDLER_PREFERENCE
end
+ # Adds a view_path to the front of the view_paths array.
+ # This change affects the current request only.
+ #
+ # @template.prepend_view_path("views/default")
+ # @template.prepend_view_path(["views/default", "views/custom"])
+ #
+ def prepend_view_path(path)
+ @view_paths.unshift(*path)
+ end
+
+ # Adds a view_path to the end of the view_paths array.
+ # This change affects the current request only.
+ #
+ # @template.append_view_path("views/default")
+ # @template.append_view_path(["views/default", "views/custom"])
+ #
+ def append_view_path(path)
+ @view_paths.push(*path)
+ end
+
private
def find_full_template_path(template_path, extension)
file_name = "#{template_path}.#{extension}"