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.

render_to_string :partial sets response.content_type

#1182

Tested on Edge Rails:

The following controller code produces a different content type header on Rails 2.1 and 2.2:


class TestController < ApplicationController
  def index
    render(:json => {:content => render_to_string(:partial => 'test') } )
  end
end

Expected Content Type: application/json

Rails 2.1 Content Type: application/json

Rails 2.2 Content Type: text/html

In Rails 2.1 response.content_type is still nil after render_to_string. In 2.2 render_to_string :partial changes response.content_type to text/html. Because of this the render :json call will not set the content_type correctly.

Reported by Andreas Gerauer · October 7th, 2008 @ 10:12 AM

State: resolved
Milestone: none
Assigned to: josh josh
Importance: none

Activity

  1. vibha
    vibha
    • Tag changed from 2.2, actionpack, content_type, partial, render_to_string to 2.2, actionpack, content_type, partial, render_to_string

    working on Rails 2.1.0, i did same

    and got response.content_type as "application/json" for Rails 2.1

    October 24th, 2008 @ 11:44 AM

  2. DHH
    DHH
    • Milestone cleared.
    • Assigned user set to josh

    October 30th, 2008 @ 11:19 AM

  3. Repository
    Repository
    • State changed from new to resolved

    (from [2092687bcb35a3d30e1d05d3f5f461d8f4e8f9b7]) Ensure content type gets reset after render_to_string [#1182 render_to_string :partial sets response.content_type state:resolved] http://github.com/rails/rails/co...

    October 30th, 2008 @ 08:26 PM