2

So when running my rake task, I get back an uninitialized constant error, referring to one of my classes. Googling the error just points to a ton of results saying you need to add '=> :environment' onto the definition of your task, but I've already done that. Would the fact I'm using mongodb change anything? Here's my code:

namespace :db do
  task :betagen => :environment do
    key = BetaKey.create!(key: ARGV[0], limit: (ARGV[1] or -1))
    puts "Beta key '" + key.key + "' created."
  end
end

(the BetaKey is what's causing the error.)

6
  • What's the full error? (i.e. which constant is uninitialized?)
    – d11wtq
    Jun 26, 2011 at 6:10
  • uninitialized constant BetaKey (as mentioned) Jun 26, 2011 at 6:13
  • Is beta_key.rb in your app/models directory and is the class name capitalized the same way?
    – d11wtq
    Jun 26, 2011 at 6:18
  • I have app/models/betakey.rb and it's capitalized as BetaKey. I'll go ahead and try with the underscore. Jun 26, 2011 at 6:23
  • yeah that fixed it, thanks :P. I can accept an answer from you if you add one. Jun 26, 2011 at 6:24

1 Answer 1

0

(As per comment)

Make sure your class file is named beta_key.rb (with the underscore) if the class is camel-cased as BetaKey, since this is what the autoloader expects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.