Skip to content
This repository
Browse code

Merge pull request #5603 from drogus/fix-rendered-format-for-render-p…

…artial

Fix rendered format for render partial
  • Loading branch information...
commit e31ec4700b9e1ca4726cff46fd68442fd6364b7b 2 parents 3eb5be6 + 449a4fc
José Valim authored March 27, 2012
10  actionpack/lib/action_view/renderer/partial_renderer.rb
@@ -221,6 +221,14 @@ def render(context, options, block)
221 221
       setup(context, options, block)
222 222
       identifier = (@template = find_partial) ? @template.identifier : @path
223 223
 
  224
+      @lookup_context.rendered_format ||= begin
  225
+        if @template && @template.formats.present?
  226
+          @template.formats.first
  227
+        else
  228
+          formats.first
  229
+        end
  230
+      end
  231
+
224 232
       if @collection
225 233
         instrument(:collection, :identifier => identifier || "collection", :count => @collection.size) do
226 234
           render_collection
@@ -273,8 +281,6 @@ def setup(context, options, block)
273 281
       @block   = block
274 282
       @details = extract_details(options)
275 283
 
276  
-      @lookup_context.rendered_format ||= formats.first
277  
-
278 284
       if String === partial
279 285
         @object     = options[:object]
280 286
         @path       = partial
13  actionpack/test/controller/render_test.rb
@@ -543,6 +543,10 @@ def partial
543 543
     render :partial => 'partial'
544 544
   end
545 545
 
  546
+  def partial_html_erb
  547
+    render :partial => 'partial_html_erb'
  548
+  end
  549
+
546 550
   def render_to_string_with_partial
547 551
     @partial_only = render_to_string :partial => "partial_only"
548 552
     @partial_with_locals = render_to_string :partial => "customer", :locals => { :customer => Customer.new("david") }
@@ -1267,6 +1271,15 @@ def test_should_render_html_formatted_partial
1267 1271
     assert_equal "text/html", @response.content_type
1268 1272
   end
1269 1273
 
  1274
+  def test_render_html_formatted_partial_even_with_other_mime_time_in_accept
  1275
+    @request.accept = "text/javascript, text/html"
  1276
+
  1277
+    get :partial_html_erb
  1278
+
  1279
+    assert_equal "partial.html.erb", @response.body.strip
  1280
+    assert_equal "text/html", @response.content_type
  1281
+  end
  1282
+
1270 1283
   def test_should_render_html_partial_with_formats
1271 1284
     get :partial_formats_html
1272 1285
     assert_equal "partial html", @response.body
1  actionpack/test/fixtures/test/_partial_html_erb.html.erb
... ...
@@ -0,0 +1 @@
  1
+<%= "partial.html.erb" %>

0 notes on commit e31ec47

Please sign in to comment.
Something went wrong with that request. Please try again.