whenever gem schedule.rb file: doesn't recognize RAILS_ROOT variable

Whenever doesn't require or depend on Rails at all, so when it runs, RAILS_ROOT is not defined, however because whenever's schedule.rb is generally kept in /config/schedule.rb, we can make an assumption that it is in a rails project, and set our own RAILS_ROOT like this:

# in schedule.rb
RAILS_ROOT = File.dirname(__FILE__) + '/..'

Edit: in the case that you actually need Rails loaded, do this:

# in schedule.rb
# this will require config/environment and load your entire rails environment
require File.expand_path(File.dirname(__FILE__) + "/environment")

The whenever developer already answered this question, check this out https://github.com/javan/whenever/issues/81

Javan Whenever no longer attempts to load your Rails environment. However, it does automatically set a path variable to the directory whenever was executed from. This should work just the same:

set :output, "#{path}/log/cron.log"

In Rails 4 try with:

require File.expand_path(File.dirname(__FILE__) + "/../config/environment")

in your schedule.rb file. This way you also have access to all your active-record models and initializers.