I've got a simple little rake script that is supposed to populate the database with some data that I've already put together. However, even though it looks like it should work, I get an error telling me there is no database connection. I'm still at the "development status" and RAILS_ENV=development is set. Rails is happy, but not rake...
require 'rake'
namespace :load_drugs do
desc "Loads drugs into the tables associated with Drug Classification"
task :from_file, [:filename] => [:environment] do |t, args|
puts "Loading data from: #{args[:filename]}"
File.open(args[:filename]).each_line() do |line|
cls, generic,names = line.split("\t")
names = names.split(",")
cls = DrugClassification.find_or_create(cls)
end
end
end
I'm using rails 4 and ruby 2.1 and the sqlite3 gem. My database exists in development and rails is fine. I'm brand new to Rails 4, so it could just be a dumb rails 4 problem.
The actual error is: undefined method `find_or_create' for DrugClassification(no database connection):Class