So a bunch of mailing methods in Article controller, that mix different types of articles with different users. All work fine when called from somewhere within Rails. But they need to be executed during the week by cron. What goes in place of "xxxx" in the rake file to tell it to execute the "10_am_action" method in the Article controller?
articles_controller.rb:
def 10_am_action
[sends the right e-mails to the right users]
end
Cron:
0 10 * * 0 cd /data/website/current && RAILS_ENV=production bundle exec rake emails:10_am
emails.rake:
namespace :briefings do
desc "10 am e-mails"
task :10_am => :environment do
xxxxxx
end
end
You can't because controllers are bound to HTTP.
However, you can refactor your code and extract the email sending logic to a mailer, and call that mailer from both your controller and your rake task.