Santosh Kumbhar
Santosh Kumbhar

Reputation: 313

How to Clear log using in rails?

I would like to know how to clear Log in using scheduler?.

I have tried rake log:clear

# app/lib/task/schedular.rake
desc 'clear logs'
task :clear_log => :environment do
  DailyAttendance.clear_logs
end

Error

bundle exec rake atte_task:clear_log

rake aborted!

NoMethodError: undefined method `clear_logs' for #<Class:0x000000098863b0>
/home/cpu053/.rvm/gems/ruby-2.2.1/gems/activerecord-4.2.4/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
/home/cpu053/workspace/hrms/lib/tasks/schedular.rake:20:in `block (2 levels) in <top (required)>'
/home/cpu053/.rvm/gems/ruby-2.2.1/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/home/cpu053/.rvm/gems/ruby-2.2.1@global/bin/bundle:23:in `load'
/home/cpu053/.rvm/gems/ruby-2.2.1@global/bin/bundle:23:in `<main>'
Tasks: TOP => atte_task:clear_log
(See full trace by running task with --trace)

Upvotes: 1

Views: 7139

Answers (2)

Santosh Kumbhar
Santosh Kumbhar

Reputation: 313

config/schedule.rb

every 4.hours do 
  rake 'log:clear'
end

Upvotes: 2

maulik bafalipara
maulik bafalipara

Reputation: 248

There are two possibility

1) you're rake task execution command is wrong with name space please try this.

bundle exec rake schedular:clear_log

2) DailyAttendance model in clear_logs method is wrong Please make it self method.

self.clear_logs

Upvotes: 1

Related Questions