Skip to content

Instantly share code, notes, and snippets.

@aravindgd
Created June 30, 2014 13:36
Show Gist options
  • Save aravindgd/21ec30146e99b5716cd9 to your computer and use it in GitHub Desktop.
Save aravindgd/21ec30146e99b5716cd9 to your computer and use it in GitHub Desktop.
Uploading CSV rails
namespace :lawyer_city do
desc "Import lawyer data"
task :all => :environment do
import_lawyer_personal_date
end
def import_lawyer_personal_date
records = []
File.open(Rails.root.join("public/lawyer_city.csv") , 'r').each do |line|
s = line.split(',')
records << s
end
records.each_with_index do |record, index|
puts "+++++++++++++++++++++++++++++++++++++++++++++"
puts index
puts "+++++++++++++++++++++++++++++++++++++++++++++"
lawyer=Lawyer.new(name: record[1],code: record[0], years_of_experience: record[2],location: record[3],rating: record[4])
if lawyer.save!
puts "Lawyer data has been saved"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment