title: Call Application Controller functions from Rake task
body: <p>I want to call a function in my ApplicationController from a rake task. I've added the => :environment tag, but it just doesn't want to work.</p>
  
  <p>Here is my stripped down code-</p>
  
  <pre><code>lib\taks\autoscrape.rake:
   desc "This task will scrape all the movies without info"
    task(:autoscrape =&gt; :environment) do
      require 'application'  #probably extraneous
      require File.dirname(__FILE__) + '/../../config/environment' #probably extraneous
      unless ApplicationController.is_admin?
        logger.error = "Sorry, you're not allowed to do that"
        return
      end
  
  
  app\controller\application_controller.rb:
  class ApplicationController &lt; ActionController::Base
    helper :all # include all helpers, all the time
  
    def is_admin?
          session[:is_admin] &amp;&amp; session[:is_admin] &gt; 0
    end
  end
  
  result:
  rake scrape:autoscrape --trace
  ** Invoke scrape:autoscrape (first_time)
  ** Invoke environment (first_time)
  ** Execute environment
  ** Execute scrape:autoscrape
  rake aborted!
  undefined method `is_admin?' for ApplicationController:Class
  E:/Dropbox/My Dropbox/Ruby/moviecat/lib/tasks/autoscrape.rake:11
  </code></pre>
  
  <p>My other controllers call this code all the time, no problems. How can my Rake task call this code? This is greatly simplified, it is part of a bigger problem, i would like to reuse more code.</p>
  
  <p>Thanks!!</p>