From 297a579de4f8cb8d8144b18d85ee370558c0977c Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Tue, 30 May 2017 11:12:34 -0300 Subject: Create MissingExactTemplate exception with separate template --- .../action_dispatch/middleware/exception_wrapper.rb | 12 +++++++----- .../templates/rescues/missing_exact_template.html.erb | 19 +++++++++++++++++++ .../templates/rescues/missing_exact_template.text.erb | 3 +++ 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 actionpack/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb create mode 100644 actionpack/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.text.erb (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb b/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb index d1b4508378..f05c69137b 100644 --- a/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb +++ b/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb @@ -12,6 +12,7 @@ module ActionDispatch "ActionController::UnknownHttpMethod" => :method_not_allowed, "ActionController::NotImplemented" => :not_implemented, "ActionController::UnknownFormat" => :not_acceptable, + "ActionController::MissingExactTemplate" => :not_acceptable, "ActionController::InvalidAuthenticityToken" => :unprocessable_entity, "ActionController::InvalidCrossOriginRequest" => :unprocessable_entity, "ActionDispatch::Http::Parameters::ParseError" => :bad_request, @@ -22,11 +23,12 @@ module ActionDispatch ) cattr_accessor :rescue_templates, default: Hash.new("diagnostics").merge!( - "ActionView::MissingTemplate" => "missing_template", - "ActionController::RoutingError" => "routing_error", - "AbstractController::ActionNotFound" => "unknown_action", - "ActiveRecord::StatementInvalid" => "invalid_statement", - "ActionView::Template::Error" => "template_error" + "ActionView::MissingTemplate" => "missing_template", + "ActionController::RoutingError" => "routing_error", + "AbstractController::ActionNotFound" => "unknown_action", + "ActiveRecord::StatementInvalid" => "invalid_statement", + "ActionView::Template::Error" => "template_error", + "ActionController::MissingExactTemplate" => "missing_exact_template", ) attr_reader :backtrace_cleaner, :exception, :line_number, :file diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb new file mode 100644 index 0000000000..3621ea81de --- /dev/null +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb @@ -0,0 +1,19 @@ +
+

No template for interactive request

+
+ +
+

<%= h @exception.message %>

+ +

+ NOTE!
+ Unless told otherwise, Rails expects an action to render a template with the same name,
+ contained in a folder named after its controller. + + If this controller is an API responding with 204 (No Content),
+ which does not require a template, + then this error will occur when trying to access it via browser,
+ since we expect an HTML template + to be rendered for such requests. If that's the case, carry on. +

+
diff --git a/actionpack/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.text.erb b/actionpack/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.text.erb new file mode 100644 index 0000000000..fcdbe6069d --- /dev/null +++ b/actionpack/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.text.erb @@ -0,0 +1,3 @@ +Missing exact template + +<%= @exception.message %> -- cgit v1.2.3