Hi,
First of all very sorry for this long post. I am trying to save my csv data to table items which is associated with Item model.
This is what my csv have:
‘name’;‘number’;‘sub_category_id’;‘category_id’;‘quantity’;‘sku’; ‘description’;‘cost_price’;‘selling_price’
‘Uploaded Item Number 1’;‘54’;‘KRT’;‘WN’;‘67’;‘WNKRT0054’;‘Some Description here!!’;‘780’;‘890’
‘Uploaded Item Number 2’;‘74’;‘KRT’;‘WN’;'98;‘WNKRT0074’;‘Some Description here!!’;‘8660’;‘9790’
First row show the fields for items table.
Here I am using fastercsv to process my csv and paperclip to upload.
I am able to process file read content and able to fill up the field too here is the processing code:
def proc_csv
@import = Import.find(params[:id])
@lines = parse_csv_file(@import.csv.path)
@lines.shift
@lines.each do |line , j|
unless line.nil?
line_split = line.split(“;”)
unless ((line_split[0].nil?) or (line_split[1].nil?) or (line_split[2].nil?) or (line_split[3].nil?) or (line_split[4].nil?) or (line_split[5].nil?))
I used puts to get to know about what’s going on.
puts "*“50+“line_split[0]: #{line_split[0]}”+"”*50
puts "*“50+“line_split[1]: #{line_split[1]}”+"”*50
puts "*“50+“line_split[2]: #{line_split[2]}”+"”*50
puts "*“50+“line_split[3]: #{line_split[3]}”+"”*50
puts "*“50+“line_split[4]: #{line_split[4]}”+"”*50
puts "*“50+“line_split[5]: #{line_split[5]}”+"”*50
puts "*“50+“line_split[6]: #{line_split[6]}”+"”*50
puts "*“50+“line_split[7]: #{line_split[7]}”+"”*50
puts "*“50+“line_split[8]: #{line_split[8]}”+"”*50
@item = [:name => line_split[0], :number => line_split[1], :sub_category_id => line_split[2],:category_id => line_split[3],:quantity => line_split[4], :sku => line_split[5], :description => line_split[6], :cost_price => line_split[7], :selling_price => line_split[8]]
puts “#”*100+“@item is: #{@item.inspect}”+“#”*100
end
end
end
redirect_to import_path(@import)
end
but the problem is that when it process it and when I check the @item in console it looks like this:
####################################################################################################@item is: [{:quantity=>“\000’\0006\0007\000’\000”, :name=>“\000’\000U\000p\000l\000o\000a\000d\000e\000d\000 \000I\000t\000e\000m\000 \000N\000u\000m\000b\000e\000r\000 \0001\000’\000”, :sku=>“\000’\000W\000N\000K\000R\000T\0000\0000\0005\0004\000’\000”, :cost_price=>“\000’\0007\0008\0000\000’\000”, :number=>“\000’\0005\0004\000’\000”, :selling_price=>“\000’\0008\0009\0000\000’\000”, :sub_category_id=>“\000’\000K\000R\000T\000’\000”, :description=>“\000’\000S\000o\000m\000e\000 \000D\000e\000s\000c\000r\000i\000p\000t\000i\000o\000n\000 \000h\000e\000r\000e\000!\000!\000’\000”, :category_id=>“\000’\000W\000N\000’\000”}]####################################################################################################
####################################################################################################@item is: [{:quantity=>“\000’\0009\0008\000”, :name=>“\000’\000U\000p\000l\000o\000a\000d\000e\000d\000 \000I\000t\000e\000m\000 \000N\000u\000m\000b\000e\000r\000 \0002\000’\000”, :sku=>“\000’\000W\000N\000K\000R\000T\0000\0000\0007\0004\000’\000”, :cost_price=>“\000’\0008\0006\0006\0000\000’\000”, :number=>“\000’\0007\0004\000’\000”, :selling_price=>“\000’\0009\0007\0009\0000\000’\000”, :sub_category_id=>“\000’\000K\000R\000T\000’\000”, :description=>“\000’\000S\000o\000m\000e\000 \000D\000e\000s\000c\000r\000i\000p\000t\000i\000o\000n\000 \000h\000e\000r\000e\000!\000!\000’\000”, :category_id=>“\000’\000W\000N\000’\000”}]####################################################################################################
Can anyone kindly tell me why am I getting this kind of string instead of simple string I entered in my csv file? And because of this it’s not being saved into the table too,
I have tried all possible formats but nothing seems to be working. I want “Uploaded Item Number 1” instead of
“\000’\0006\0007\000’\000”, :name=>“\000’\000U\000p\000l\000o\000a\000d\000e\000d\000 \000I\000t\000e\000m\000 \000N\000u\000m\000b\000e\000r\000 \0001\000’\000” . Any help will be appreciated. Thanks in advance