# Multiple renderings of Partials

**URL:** <https://www.ruby-forum.com/t/multiple-renderings-of-partials/163331>\
**Category:** Rails\
**Created:** [March 19, 2009, 10:15am UTC](https://www.ruby-forum.com/t/multiple-renderings-of-partials/163331 "2009-03-19T10:15:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7ba0ec/32.png) [@Guha](https://www.ruby-forum.com/u/Guha)\
**Post date:** [March 19, 2009, 10:15am UTC](https://www.ruby-forum.com/t/multiple-renderings-of-partials/163331/1 "2009-03-19T10:15:43Z")

</div>

This is what I see in the developer log

`Processing ProductsController#display_variant_parameters (for
127.0.0.1 at 2009-03-18 17:50:25) [POST]
  Session ID: 33b195edc7a6946365ae55efe5e349dd
  Parameters:
{"authenticity_token"=>"bc18fccde1f10c5f100e78adbbac88c2f6c535b3",
"product"=>{"product_category_id"=>"7"},
"action"=>"display_variant_parameters", "controller"=>"products"}
   [4;36;1mUser Columns (0.008000) [0m [0;1mSHOW FIELDS FROM
`users` [0m
   [4;35;1mUser Load (0.006000) [0m [0mSELECT * FROM `users` WHERE
(`users`.`id` = 1) LIMIT 1 [0m
7
Rendered products/_product_variant_parameter (0.00400)
Rendered products/_product_variant_parameter (0.00000)
Rendered products/_product_variant_parameter (0.00100)
Rendered products/_product_variant_parameter (0.00100)
Completed in 0.04100 (24 reqs/sec) | Rendering: 0.00900 (21%) | DB:
0.01400 (34%) | 200 OK [http://localhost/products/
display_variant_parameters]`  
Why is the \_product\_variant\_parameter partials getting rendered 4  
times ?

My controller code is as follows. For simplicity sake, I have replaced  
the original business logic with a hardcoded hash. The behavior is the  
same.

[code=]def display\_variant\_parameters

# Parameters:

{“authenticity\_token”=\>“9c0dc9b28f19a5b746cfa17e6450d61eacdca816”,  
“product”=\>{“product\_category\_id”=\>“6”},  
“action”=\>“display\_variant\_parameters”, “controller”=\>“products”}  
logger.info params[:product][:product\_category\_id]  
@variants\_params\_hash = {1 =\> “password0”,  
“adi” =\> “password1”,  
“aaron” =\> “password2” }  
@variants\_params\_hash.merge({“sam1” =\> “password3”})  
@variants\_params\_hash.merge!({“sam2” =\> “password3”})  
render :partial =\> “product\_variant\_parameter”, :collection =\>  
@variants\_params\_hash  
end[/code]  
The same is invoked on change of the select box

[code=] \<%=  
@product\_categories = ProductCategory.find(:all, :order =\>  
“title” )  
f.collection\_select(:product\_category\_id,  
@product\_categories, :id, :title , {:prompt =\> true},  
{:onchange =\>remote\_function(:update =\>  
“product\_variants\_div”,  
:url =\> { :action =\> :display\_variant\_parameters},  
:with =\> ‘Form.Element.serialize(this)’)  
} )

```
    %>[/code]

```

The controller is not invoked multiple times. It is only the rendering  
of the partials, as per the development log. This is just driving me  
crazy for the last 3 days

---

<div class="post-metadata">

**Author:** ![Guha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/7ba0ec/32.png) [@Guha](https://www.ruby-forum.com/u/Guha)\
**Post date:** [March 19, 2009, 10:18am UTC](https://www.ruby-forum.com/t/multiple-renderings-of-partials/163331/2 "2009-03-19T10:18:04Z")

</div>

On Mar 19, 1:03 am, Guha [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> This is what I see in the developer log

> @variants\_params\_hash = {1 =\> “password0”,  
> “adi” =\> “password1”,  
> “aaron” =\> “password2” }  
> @variants\_params\_hash.merge({“sam1” =\> “password3”})  
> @variants\_params\_hash.merge!({“sam2” =\> “password3”})  
> render :partial =\> “product\_variant\_parameter”, :collection =\>  
> @variants\_params\_hash

You’ve got a collection with 4 elements in it and you’re asking rails  
to render the partial for each element in the collection. Why is it a  
surprise that that partial is rendered 4 times ?

Fred
