diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/path_set.rb | 32 | ||||
-rw-r--r-- | actionpack/lib/action_view/template/error.rb | 8 | ||||
-rw-r--r-- | actionpack/lib/action_view/template/resolver.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/mime_responds_test.rb | 2 |
4 files changed, 33 insertions, 11 deletions
diff --git a/actionpack/lib/action_view/path_set.rb b/actionpack/lib/action_view/path_set.rb index a7078b8232..2a54b12f78 100644 --- a/actionpack/lib/action_view/path_set.rb +++ b/actionpack/lib/action_view/path_set.rb @@ -11,23 +11,41 @@ module ActionView #:nodoc: end def find(*args) - template = find_all(*args).first - template or raise MissingTemplate.new(self, "{#{args[1].join(',')},}/#{args[0]}", args[3], args[2]) + if template = find_first(*args) + template + else + raise MissingTemplate.new(self, *args) + end end def find_all(path, prefixes = [], *args) - templates = [] prefixes.each do |prefix| + templates = [] + each do |resolver| - templates << resolver.find_all(path, prefix, *args) + templates.concat resolver.find_all(path, prefix, *args) end - # return templates unless templates.flatten!.empty? XXX this was original behavior; turns this method into find_some, but probably makes it faster + + return templates unless templates.empty? end - templates.flatten + + [] + end + + def find_first(path, prefixes = [], *args) + prefixes.each do |prefix| + each do |resolver| + if template = resolver.find_all(path, prefix, *args).first + return template + end + end + end + + nil end def exists?(*args) - find_all(*args).any? + !!find_first(*args) end protected diff --git a/actionpack/lib/action_view/template/error.rb b/actionpack/lib/action_view/template/error.rb index ff256738a9..d7d98e1dd5 100644 --- a/actionpack/lib/action_view/template/error.rb +++ b/actionpack/lib/action_view/template/error.rb @@ -27,7 +27,7 @@ module ActionView class MissingTemplate < ActionViewError #:nodoc: attr_reader :path - def initialize(paths, path, details, partial) + def initialize(paths, path, prefixes, partial, details, *) @path = path display_paths = paths.compact.map{ |p| p.to_s.inspect }.join(", ") template_type = if partial @@ -38,7 +38,11 @@ module ActionView 'template' end - super("Missing #{template_type} #{path} with #{details.inspect} in view paths #{display_paths}") + searched_paths = prefixes.map { |prefix| [prefix, path].join("/") } + + out = "Missing #{template_type} #{searched_paths.join(", ")} with #{details.inspect}. Searched in:\n" + out += paths.compact.map { |p| " * #{p.to_s.inspect}\n" }.join + super out end end diff --git a/actionpack/lib/action_view/template/resolver.rb b/actionpack/lib/action_view/template/resolver.rb index 0dccc99d14..d23aa5ef85 100644 --- a/actionpack/lib/action_view/template/resolver.rb +++ b/actionpack/lib/action_view/template/resolver.rb @@ -47,7 +47,7 @@ module ActionView path end - # Hnadles templates caching. If a key is given and caching is on + # Handles templates caching. If a key is given and caching is on # always check the cache before hitting the resolver. Otherwise, # it always hits the resolver but check if the resolver is fresher # before returning it. diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 98c9d43b93..fe14d24327 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -565,7 +565,7 @@ class RespondWithController < ActionController::Base def using_resource_with_action respond_with(resource, :action => :foo) do |format| - format.html { raise ActionView::MissingTemplate.new([], "foo/bar", {}, false) } + format.html { raise ActionView::MissingTemplate.new([], "bar", ["foo"], {}, false) } end end |