Reputation: 1535
can anybody suggest me where i am going wrong?
i tried to execute below task, but ended up with
rake aborted!
NoMethodError: undefined method 'perform' for main:Object
this is my rake task
task :update_state_for_search_request => :environment do
t_last = MyModule.where("condition").last.id
t_first = 0
until t_first >= t_last do
t_first=print_id(t_first)
end
def perform(sid)
# action
my_data = MyModule.where("name='abcd' and id > #{sid}").limit(1000)
# action
return my_data.last.id
end
end
Upvotes: 0
Views: 1593
Reputation: 16506
You are defining method inside rake task which is the issue here. Define it outside your task.
task :update_state_for_search_request => :environment do
t_last = MyModule.where("condition").last.id
t_first = 0
until t_first >= t_last do
t_first=print_id(t_first)
end
end
def perform(sid)
# action
my_data = MyModule.where("name='abcd' and id > #{sid}").limit(1000)
# action
return my_data.last.id
end
Also refer to this SO: def block in rake task
Upvotes: 1