Improve missing template error messages a little bit.

This commit is contained in:
José Valim 2010-01-31 10:24:38 +01:00
parent 48459c8278
commit b3a028259f
3 changed files with 13 additions and 8 deletions

View File

@ -6,15 +6,20 @@ module ActionView #:nodoc:
end
class MissingTemplate < ActionViewError #:nodoc:
attr_reader :path, :action_name
attr_reader :path
def initialize(paths, path, template_format = nil)
def initialize(paths, path, details, partial)
@path = path
@action_name = path.split("/").last.split(".")[0...-1].join(".")
full_template_path = path.include?('.') ? path : "#{path}.erb"
display_paths = paths.compact.join(":")
template_type = (path =~ /layouts/i) ? 'layout' : 'template'
super("Missing #{template_type} #{full_template_path} in view path #{display_paths}")
template_type = if partial
"partial"
elsif path =~ /layouts/i
'layout'
else
'template'
end
super("Missing #{template_type} #{path} with #{details.inspect} in view path #{display_paths}")
end
end

View File

@ -45,7 +45,7 @@ module ActionView #:nodoc:
end
end
raise ActionView::MissingTemplate.new(self, "#{prefix}/#{path} - #{details.inspect} - partial: #{!!partial}")
raise ActionView::MissingTemplate.new(self, "#{prefix}/#{path}", details, partial)
end
def exists?(path, extension = nil, prefix = nil, partial = false)

View File

@ -499,7 +499,7 @@ class RespondWithController < ActionController::Base
def using_resource_with_action
respond_with(resource, :action => :foo) do |format|
format.html { raise ActionView::MissingTemplate.new([], "method") }
format.html { raise ActionView::MissingTemplate.new([], "foo/bar", {}, false) }
end
end