rake tast can't access rails.cache

Posted by mark on Stack Overflow See other posts from Stack Overflow or by mark
Published on 2010-05-07T19:55:00Z Indexed on 2010/05/07 19:58 UTC
Read the original article Hit count: 177

Filed under:
|
|

Hi

I want to call a rake task from a cron job that stores remote weather data in the rails cache. However, I must be doing something pretty wrong here because I cannot find any solution through countless fruitless searches.

Say I define and call this task

namespace :weather do
  desc "Store weather from remote source to cache"
  task :cache do
    Rails.cache.write('weather_data', Date.today)
  end
end

I get the error

Anonymous modules have no name to be referenced by

Which leads me to believe the rails cache isn't available. Outputting Rails.class from the rake file gives me Module but Rails.cache.class again returns the above error. Do I need to include something here? Am I just hopeless at internet? :)

Thanks in advance.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about rake