title: RoR Error trying to run task: `require': cannot load such file -- rack/handler/rake
body: <p>I'm having a problem whenever I try to run a Rake task that deletes certain records from the database older than 5 days, I just wanted to test it out first so I used just 1 day instead, anyway, after I execute <code>rails s RAILS_ENV=production rake delete:delete_5_old_days</code> I get that error: <code>require': cannot load such file -- rack/handler/rake</code></p>
  
  <p>This is the whole traceback </p>
  
  <pre><code>/home/miguel/.rvm/gems/ruby-2.3.1/gems/bundler-1.14.5/lib/bundler/runtime.rb:91:in `require': cannot load such file -- rack/handler/rake (LoadError)
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/bundler-1.14.5/lib/bundler/runtime.rb:91:in `block (2 levels) in require'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/bundler-1.14.5/lib/bundler/runtime.rb:86:in `each'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/bundler-1.14.5/lib/bundler/runtime.rb:86:in `block in require'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/bundler-1.14.5/lib/bundler/runtime.rb:75:in `each'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/bundler-1.14.5/lib/bundler/runtime.rb:75:in `require'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/bundler-1.14.5/lib/bundler.rb:107:in `require'
      from /home/miguel/RubymineProjects/adopt_bronze/config/application.rb:7:in `&lt;top (required)&gt;'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:88:in `require'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:88:in `block in server'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:85:in `tap'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:85:in `server'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/railties-5.0.1/lib/rails/commands.rb:18:in `&lt;top (required)&gt;'
      from /home/miguel/RubymineProjects/adopt_bronze/bin/rails:9:in `require'
      from /home/miguel/RubymineProjects/adopt_bronze/bin/rails:9:in `&lt;top (required)&gt;'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `load'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `call'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/client/command.rb:7:in `call'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/client.rb:30:in `run'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/spring-2.0.1/bin/spring:49:in `&lt;top (required)&gt;'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `load'
      from /home/miguel/.rvm/gems/ruby-2.3.1/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `&lt;top (required)&gt;'
      from /home/miguel/RubymineProjects/adopt_bronze/bin/spring:15:in `require'
      from /home/miguel/RubymineProjects/adopt_bronze/bin/spring:15:in `&lt;top (required)&gt;'
      from bin/rails:3:in `load'
      from bin/rails:3:in `&lt;main&gt;'
  </code></pre>
  
  <p>And the task that I'm trying to execute is this:</p>
  
  <pre><code>namespace :delete do
    desc 'Delete records older than 5 days'
    task delete_5_days_old: :environment do
      Post.where(['created_at &lt; ?, 1_day_ago']).each do |post|
        post.destroy
      end
    end
  
  end
  </code></pre>