Note that there are some explanatory texts on larger screens.

plurals
  1. PORequire CSV Issue
    primarykey
    data
    text
    <p>I'm running a RAils 3.1,ruby 1.9.2 app and I've a issue with CSV;I must import data from csv file; this is my code:</p> <pre><code>def bulk_operations require 'csv' last_asset = "" last_serial = "" if request.path.include? "ingress_transport_document" transport_document_id = params[:ingress_transport_document_id] td = IngressTransportDocument.find(transport_document_id) ingress = true; elsif request.path.include? "egress_transport_document" transport_document_id = params[:egress_transport_document_id] td = EgressTransportDocument.find(transport_document_id) end if params[:dump_me] begin # @parsed_file=CSV::Reader.parse(params[:dump_me][:file],';',"\n") CSV.foreach(params[:dump_me][:file]) do |row| bw=BulkWarehouse.new bw.serial = row[0] bw.asset = row[1] logger.debug "#{bw.serial},#{bw.asset} --&gt; #{bw.serial.strip}" # # Cerco la presenza di warehouse se la bolla e di tipo aggiornamento # if !bw.serial.strip.empty? &amp;&amp; !bw.asset.strip.empty? &amp;&amp; update_warehouse warehouse = Warehouse.find_by_serial_and_asset(bw.serial.strip,bw.asset.strip) elsif !bw.serial.strip.empty? &amp;&amp; update_warehouse warehouse = Warehouse.find_by_serial(bw.serial.strip) elsif !bw.asset.strip.empty? &amp;&amp; update_warehouse warehouse = Warehouse.find_by_asset(bw.asset.strip) end if warehouse &amp;&amp; update_warehouse bw.warehouse_id = warehouse.id elsif update_warehouse @wh_errors[:"bulk_warehouse#{n}"] = "Prodotto non presente" end if request.path.include? "ingress_transport_document" bw.ingress_transport_document_id = transport_document_id elsif request.path.include? "egress_transport_document" bw.egress_transport_document_id = transport_document_id end if bw.save n=n+1 GC.start if n%50==0 end last_serial = row[0] last_asset = row[1] end count = sa_query flash[:notice]="Il CSV e stato importato con successo: #{n} nuovi record sono stati accodati per essere processati.&lt;br&gt;In totale hai #{count} record in attesa di essere processati." #rescue CSV::IllegalFormatError logger.debug("CSV Exception: IllegalFormatError") count = sa_query flash[:notice] = "Il CSV NON sembra essere formattato correttamente." flash[:notice] += "L'ultimo ASSET inserito e stato #{last_asset}." if !last_asset.empty? flash[:notice] += "L'ultimo SERIALE inserito e stato #{last_serial}." if !last_serial.empty? flash[:notice] += "#{n} nuovi record sono stati accodati per essere processati." flash[:notice] += "In totale hai #{count} record in attesa di essere processati." end end # update_warehouse e true solo se la bolla e di tipo da aggiornamento update_warehouse = td.transport_document_type.code == "AGE" || td.transport_document_type.code == "REP" || td.transport_document_type.code == "ASS" if params[:ingress_transport_document_id] || params[:egress_transport_document_id] self.index render :index else redirect_to :action =&gt; "index" end </code></pre> <p>and Rails give me the following errors: can't convert ActionDispatch::Http::UploadedFile into String</p> <p>Any suggestion</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload