Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

partial counters with :as [#2804 state:resolved]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit fa99de0bd054576336c940ca78f3d1b35b6e490e 1 parent 3436fdf
@jeffkreeftmeijer jeffkreeftmeijer authored jeremy committed
View
1  actionpack/lib/action_view/render/partials.rb
@@ -248,6 +248,7 @@ def collection_with_template(template = @template)
@collection.each do |object|
locals[counter_name] += 1
+ locals["#{as.to_s}_counter".to_sym] = locals[counter_name]
locals[as] = object
segments << template.render(@view, locals)
View
9 actionpack/test/controller/render_test.rb
@@ -547,6 +547,10 @@ def partial_collection_with_counter
render :partial => "customer_counter", :collection => [ Customer.new("david"), Customer.new("mary") ]
end
+ def partial_collection_with_as_and_counter
+ render :partial => "customer_counter_with_as", :collection => [ Customer.new("david"), Customer.new("mary") ], :as => :client
+ end
+
def partial_collection_with_locals
render :partial => "customer_greeting", :collection => [ Customer.new("david"), Customer.new("mary") ], :locals => { :greeting => "Bonjour" }
end
@@ -1242,6 +1246,11 @@ def test_partial_collection_with_counter
assert_equal "david0mary1", @response.body
end
+ def test_partial_collection_with_as_and_counter
+ get :partial_collection_with_as_and_counter
+ assert_equal "david0mary1", @response.body
+ end
+
def test_partial_collection_with_locals
get :partial_collection_with_locals
assert_equal "Bonjour: davidBonjour: mary", @response.body
View
1  actionpack/test/fixtures/test/_customer_counter_with_as.erb
@@ -0,0 +1 @@
+<%= client.name %><%= client_counter %>
Please sign in to comment.
Something went wrong with that request. Please try again.