ruby - Error While Importing CSV Document - 0 Records Get Added -
i getting output 0 records added when trying import csv file database. controller code :-
def add if request.post? @parsed_file=csv::reader.parse(params[:dump][:file], :headers => true) n=0 @parsed_file.each |row| c=student.new c.admission_no=row[0] c.class_roll_no=row[1] c.admission_date=row[2] c.first_name= row[3] if c.save n=n+1 gc.start if n%50==0 end end flash[:notice]="csv import successful, #{n} new records added data base" redirect_to :controller=>"data_import", :action=>"index" end end end
my ruby version 1.8.7
student table inserting data.
can 1 me out.
Comments
Post a Comment