Search code examples
ruby-on-railsrubyrake

Rake Task environment variable w/Command Line Arguments


So I was getting some "Uninitalized constants" on my rake task, and I did some googling and found that the environment variable needed to be loaded in. However im also using a command line argument and im not sure if the positioning is correct or what:

desc "Wipes Specific User"
task :clean_user => environment [:user] do |t, args|
  puts "Running clean_user for #{args[:user]}..."
  Core::Stuff.find(args[:user]).wipe_user
end

Without the environment variable somewhere I get complains about Core::Stuff being uninitialized, but Im trying to pass :user via CL. (This is just a sample rake task to make sure stuff works).

Am I missing something?

edit: Fixing the issue with: task :clean_user, [:user] => :environment however now it seems to be loading my PATH into the argument (I get an error complaining how "Core::Stuff cannot find a user id with id of "" . So it's like it's using my CL path as the ID?


Solution

  • The docs in the gem specify:

    task task_name, arguments => dependencies

    That means your code needs to be:

    task :clean_user, [:user] => :environment do |t, args|