Reputation: 5619
I want to find all database entries for a Model. The code is situated in corns.rake
task (:clean_database) do
clients = Client.all
puts "BLAAAAAAA"
puts clients.inspect
end
When I run this code I got this error:
rake aborted!
NameError: uninitialized constant Client
Upvotes: 0
Views: 49
Reputation: 32933
You need to load your Rails environment in the rake task in order for it to know about your model classes (eg Client)
task(:clean_database => :environment) do
...
note also no space between task
and (
or you'll get a warning about dodgy parentheses.
Upvotes: 1
Reputation: 51151
Your task needs environment to be loaded, so:
task clean_database: :environment do
Upvotes: 2