Forum: Ruby on Rails Multiple renderings of Partials

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
409d40e837f3a1234911df72d6de8983?d=identicon&s=25 Guha (Guest)
on 2009-03-19 10:15
(Received via mailing list)
This is what I see in the developer log
[code=]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][/code]
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
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-19 10:18
(Received via mailing list)
On Mar 19, 1:03 am, Guha <jguhara...@gmail.com> 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
This topic is locked and can not be replied to.