Hi, guys. I wrote a rake task that called a method in model A.
in app.rake
task :update_number => :environment do
A.update_method
end
in model A
def self.update_method
t1 = A.find.all
...
..
end
When I ran the rake task, it returned an error "undefined local variable
or method t1". If I copied codes in the method to app.rake, it worked
perfectly. Did I miss something when I called the method in model from
rake?
Thanks in advance.
Thank you, Bryan. It works like a charm after adding the codes you
suggested! If I run the rake task in production mode, do I need to
change something in the rake file?
You’re welcome. No need to change anything in file to run in production mode. A rake file will take the environment mode that the rails app is running in. If you need to run the rake file while rails is not running it’s going to look for the environment variable RAILS_ENV. Set that in your shell to the environment you want rake to run against and you’re good to go.
You're welcome. No need to change anything in file to run in
production
mode. A rake file will take the environment mode that the rails app is
running in. If you need to run the rake file while rails is not running
it's
going to look for the environment variable RAILS_ENV. Set that in your
shell
to the environment you want rake to run against and you're good to go.