Note that there are some explanatory texts on larger screens.

plurals
  1. PORails CSV import not functioning properly
    primarykey
    data
    text
    <p>Basically, CSV import doesn't work.</p> <p>Model Code:</p> <pre><code>def self.import(file,admin_id) spreadsheet = open_spreadsheet(file) header = spreadsheet.row(1) (2..spreadsheet.last_row).each do |i| row = Hash[[header, spreadsheet.row(i)].transpose] new_row = row.to_hash.merge(:merchant_id =&gt; admin_id) Inventory.create! new_row end end def self.open_spreadsheet(file) require 'iconv' case File.extname(file.original_filename) when ".csv" then Roo::Csv.new(file.path, nil, :ignore) when ".xls" then Roo::Excel.new(file.path, nil, :ignore) when ".xlsx" then Roo::Excelx.new(file.path, nil, :ignore) else raise "Unknown file type: #{file.original_filename}" end end </code></pre> <p>Controller action:</p> <pre><code>def import Inventory.import(params[:file],params[:admin_id]) redirect_to :inventories, :notice =&gt; "Imported Successfully." end </code></pre> <p>Import button, select file, all that working fine. On submit:</p> <blockquote> <pre><code> SyntaxError in InventoriesController#import (eval):2: syntax error, unexpected tIDENTIFIER, expecting ')' read_key(:Parts name) ^ (eval):6: syntax error, unexpected tIDENTIFIER, expecting ')' read_key_before_type_cast(:Parts name) ^ (eval):10: syntax error, unexpected tIDENTIFIER, expecting ')' write_key(:Parts name, value) ^ (eval):10: syntax error, unexpected ')', expecting '=' (eval):14: syntax error, unexpected tIDENTIFIER, expecting ')' read_key(:Parts name).present? ^ (eval):15: syntax error, unexpected $end, expecting keyword_end </code></pre> </blockquote> <p>Can someone please shed some light on this? I can't even find a good way to debug the actual method to see exactly what it tries to do and how it fails on.</p> <p>There is a template CSV file that looks like this across the header row:</p> <blockquote> <p>Parts name Parts number Quantity Cost Price Tax Location Description Is editable</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    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