Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Override content type when rendering default error file

#1478

If a template is rendered with a content type other than 'text/html', when an exception is raised and considered a non-local request, the default error file (500.html) will be rendered with the specified content type rather than 'text/html'. This can cause wonkiness in some browsers.

For example:


class DummyController < ApplicationController
  def index
    render :inline => "<%= response.bad_method %>", :content_type => 'text/plain'
  end
end

When the above method is accessed, the default file (500.html) will be rendered with a content type of 'text/plain', which will cause browsers such as Safari to render the page as plain text rather than HTML. Ugly.

A fix is attached. I spent quite a bit of time trying to come up with a test, but it looks like a test would mean adding quite a bit of code to either rescue_test.rb or render_test.rb (since it requires both the set up code for rendering as well as rescuing). If anyone can code one up, that would be great - and/or point me in the right direction.

Reported by Brady Bouchard · November 26th, 2008 @ 08:35 AM

State: resolved
Milestone: 2.x
Assigned to: josh josh
Importance: none

Activity

  1. josh
    josh
    • Tag set to bug, content_type, patch, render
    • Assigned user set to josh

    December 15th, 2008 @ 09:31 PM

  2. Repository
    Repository
    • State changed from new to resolved

    (from [33f76bb25a973a4707437064e2f963c521413fcb]) Ensure error file is sent with a 'text/html' content type [#1478 Override content type when rendering default error file state:resolved]

    Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...

    December 17th, 2008 @ 04:22 PM