Skip to content

Commit fa99de0

Browse files
Jeff Kreeftmeijerjeremy
authored andcommitted
partial counters with :as [rails#2804 state:resolved]
Signed-off-by: Jeremy Kemper <[email protected]>
1 parent 3436fdf commit fa99de0

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

actionpack/lib/action_view/render/partials.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def collection_with_template(template = @template)
248248

249249
@collection.each do |object|
250250
locals[counter_name] += 1
251+
locals["#{as.to_s}_counter".to_sym] = locals[counter_name]
251252
locals[as] = object
252253

253254
segments << template.render(@view, locals)

actionpack/test/controller/render_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,10 @@ def partial_collection_with_counter
547547
render :partial => "customer_counter", :collection => [ Customer.new("david"), Customer.new("mary") ]
548548
end
549549

550+
def partial_collection_with_as_and_counter
551+
render :partial => "customer_counter_with_as", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :client
552+
end
553+
550554
def partial_collection_with_locals
551555
render :partial => "customer_greeting", :collection => [ Customer.new("david"), Customer.new("mary") ], :locals => { :greeting => "Bonjour" }
552556
end
@@ -1242,6 +1246,11 @@ def test_partial_collection_with_counter
12421246
assert_equal "david0mary1", @response.body
12431247
end
12441248

1249+
def test_partial_collection_with_as_and_counter
1250+
get :partial_collection_with_as_and_counter
1251+
assert_equal "david0mary1", @response.body
1252+
end
1253+
12451254
def test_partial_collection_with_locals
12461255
get :partial_collection_with_locals
12471256
assert_equal "Bonjour: davidBonjour: mary", @response.body
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= client.name %><%= client_counter %>

0 commit comments

Comments
 (0)