Question

I am trying to run this custom rake task to import data into my Rails 3.1 app:

desc "Import users." 
    task :import_users => :environment do
        File.open("users.txt", "r").each do |line|
            name, email, age = line.strip.split("\t")
            u = User.new(:name => name, :email => email, :age => age)
            u.save
        end
    end

I saved the file as import_users.rake and placed it in my app's lib/tasks directory.

However when I try to run rake import_users in command line I get this error:

No such file or directory - users.txt

I placed users.txt in the same directory as the .rake file (lib/tasks directory), is that the correct location?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top