Skip to content

Commit ba16325

Browse files
committed
Improve the MissingExactTemplate errorpage
Passthrough the controller and action name to the error page.
1 parent 7ceb703 commit ba16325

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

actionpack/lib/action_controller/metal/exceptions.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,13 @@ def initialize(message = nil)
9292
end
9393

9494
class MissingExactTemplate < UnknownFormat # :nodoc:
95+
attr_reader :controller, :action_name
96+
97+
def initialize(message, controller, action_name)
98+
@controller = controller
99+
@action_name = action_name
100+
101+
super(message)
102+
end
95103
end
96104
end

actionpack/lib/action_controller/metal/implicit_render.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def default_render
4242
raise ActionController::UnknownFormat, message
4343
elsif interactive_browser_request?
4444
message = "#{self.class.name}\##{action_name} is missing a template for request formats: #{request.formats.map(&:to_s).join(',')}"
45-
raise ActionController::MissingExactTemplate, message
45+
raise ActionController::MissingExactTemplate.new(message, self.class, action_name)
4646
else
4747
logger.info "No template found for #{self.class.name}\##{action_name}, rendering head :no_content" if logger
4848
super

actionpack/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<strong>NOTE:</strong> Rails usually expects a controller action to render a view template with the same name.
1111
</p>
1212
<p>
13-
For example, a <code>BooksController#index</code> action defined in <code>app/controllers/books_controller.rb</code> should have a corresponding view template
14-
in a file named <code>app/views/books/index.html.erb</code>.
13+
For example, a <code><%= @exception.controller %>#<%= @exception.action_name %></code> action defined in <code>app/controllers/<%= @exception.controller.controller_path %>_controller.rb</code> should have a corresponding view template
14+
in a file named <code>app/views/<%= @exception.controller.controller_name %>/<%= @exception.action_name %>.html.erb</code>.
1515
</p>
1616
<p>
1717
However, if this controller is an API endpoint responding with 204 (No Content), which does not require a view template because it doesn't serve an HTML response, then this error will occur when trying to access it with a browser. In this particular scenario, you can ignore this error.

0 commit comments

Comments
 (0)