1

i have few constants declared in application_controller.rb file. Is there any way to access them in schedule.rb file of whenever gem?

Regards, Sudhir C.N.

sudhir
  • 320
  • 1
  • 5
  • 13

1 Answers1

3

The whenever gem does not include the Rails environment by default. If you wanted to do this, you would need to load Rails within your cron tasks. This is not recommended however, especially if all you need is access to some constants.

I would recommend moving your constant definitions to a config file or initializer. Then you can require that file from both your application_controller and your whenever configuration. It will consolidate the logic and give you access to those constants without having to load the entire Rails app for each invocation of whenever.

I hope that helps.

phlipper
  • 1,834
  • 15
  • 14