Hello guys and girls, I have a problem with a method (new), it is using 100% of CPU for 15/20 seconds. Follow the method below: http://pastie.org/537568 ## kits_controller.rb def new @page_title = 'Add a Kit' @kit = Kit.new @num_itens = 16 @kit_inclusions = Array.new @num_itens.times { @kit_inclusions.push(KitInclusion.new) } render :action => 'form' end def new_do kit = Kit.new(params[:form]) if kit.save params[:kit_inclusions].each do |ki| next if ki[:product_id].empty? kit_inclusion = KitInclusion.new(ki) kit_inclusion.kit_id = kit.id kit_inclusion.save end flash[:notice] = 'Kit added!' redirect_to :action => 'index' else flash[:notice] = kit.errors.full_messages.map {|fm| "<li>#{fm}</
"}
redirect_to :action => 'new' end end ## form.hmtl.erb <% form_for :form, @kit, :url => { :action => action_do } do |f| -%> <% @num_itens.times do |t| -%> <% fields_for "kit_inclusions", @kit_inclusions[t] do |i| - %> <li><label><strong>Product <%= t + 1 %>:</strong></label>< %= i.collection_select "product_id", Product.all(:conditions => {:available => true}, :order => "category_id, model ASC"), :id, :display_for_select, {:include_blank => 'Select...'}, {:onchange => "qntDefault(\'quantity_#{t}\');"} %><%= i.text_field "quantity", {:onkeydown => "return noLetters(event);", :class => 'quantity', :id => "quantity_#{t}"} %></li> <% end -%> <% end -%> <%= image_submit_tag 'btn_save.png' %></div> <%= f.hidden_field :id %> <% end -%>