title: NoMethodError: undefined method `where' for main:Object (rake task) - Rails 4
body: <p>I have a rails 4 app with a cron job that runs the following task once a day:</p>
  
  <pre><code>task :update_packs =&gt; :environment do
      @all_users = User.all
  
      @all_users.each do |user|
          today = where(:created_at =&gt; (Time.now.beginning_of_day..Time.now))
          @packs = user.default_packs
          if user.packs.today.count &gt;= 1
              puts "ERROR: User already has a record today."
          else
              user.packs.create(:amount =&gt; @packs)
          end
      end
  end
  </code></pre>
  
  <p>However, when I run the task, I get the following error: </p>
  
  <pre><code>NoMethodError: undefined method `where' for main:Object
  /home/ben/rails_projects/hartwig/lib/tasks/packs.rake:7:in `block (2 levels) in &lt;top (required)&gt;'
  /home/ben/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/relation/delegation.rb:46:in `each'
  /home/ben/.rvm/gems/ruby-2.1.1/gems/activerecord-4.1.0/lib/active_record/relation/delegation.rb:46:in `each'
  /home/ben/rails_projects/hartwig/lib/tasks/packs.rake:6:in `block in &lt;top (required)&gt;'
  /home/ben/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
  /home/ben/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `&lt;main&gt;'
  Tasks: TOP =&gt; update_packs
  </code></pre>
  
  <p>I've tried to replace <em>where</em> with <em>conditions</em>, but I get the same error. Any ideas? </p>