Created
October 4, 2010 20:54
-
-
Save anonymous/610413 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create users from csv file | |
| def create_students_from_csv | |
| @csv_file = CSV::Reader.parse(params[:csv_file]) | |
| # Did we get a file? | |
| if @csv_file | |
| c = 0 | |
| # Remove headings | |
| @csv_file.shift | |
| # Loop through our records | |
| @csv_file.each do |row| | |
| a = Account.new(:username => row[2], :email => row[2], :real_name => row[0], :account_type => 'student') | |
| a.password = rand(2**256).to_s(36)[0..7] | |
| a.active = true | |
| if a.save | |
| # Add 1 to our counter, will be used for displaying ammount of saved users | |
| c += 1 | |
| end | |
| end | |
| flash[:notice] = "CSV Import Successful, #{c} new students added to the database" | |
| redirect_to portals_path | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment