Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
2 Posts
CSV

Hi,

This code is not working in Production. I am unable to create users when importing CSV file. Using ruby 1.8.6, rails 1.2.3

require 'csv' def import_from_csv

if request.post? && (params[:csv_import].kind_of?(StringIO) || params[:csv_import].kind_of?(Tmpfile))
  @parsed_file = CSV::Reader.parse(params[:csv_import])
  n = 0
  @parsed_file.each do |row|
    @user = User.new {|user|
      # login is the first element of each line
      user.login = row[0]
      # assign an auto-generated password
      user.password = User.generate_random_password
    }
    if @user.save
      n = n+1
      GC.start if n%50==0
    end
  end
end

users.csv file: skylark14348@yahoo.com user2@gmail.com gogle_user@gmail.com december_users@redif.com

The file importing works fine in development(localhost), but not on live site

Please help me .

Rails 1.2.3? Show us error which you can see.

2 Posts
Login to add your message