title: Heroku Scheduler: undefined local variable or method `params' for CreditsController:Class
body: <p>I am trying to automate a task with Heroku Scheduler. I tested the task in local and it works. I created a temporary route for testing, and it works everytime I hit the route:</p>
  
  <pre><code>get 'create_expired_credit_lines' to: 'credits#create_expired_lines'
  </code></pre>
  
  <p>credits.controller.rb</p>
  
  <pre><code>class CreditsController &lt; ApplicationController
  ...
  
   def self.create_expired_lines
   ...
    @new_credit = Credit.new(params[:credit])
   ...
   end
  </code></pre>
  
  <p>I then created a file </p>
  
  <pre><code>app/lib/tasks/scheduler.rake
  
  desc "This task is called by the Heroku scheduler add-on"
  task :create_expired_credit_lines =&gt; :environment do
    puts "Creating expired credit lines..."
    CreditsController.create_expired_lines
    puts "done."
  end
  </code></pre>
  
  <p>When the tasks get executed, I get the following error:</p>
  
  <pre><code>2014-03-20T21:42:11.190318+00:00 app[scheduler.4496]: undefined local variable or method `params' for CreditsController:Class
  </code></pre>
  
  <p>Full log:</p>
  
  <pre><code>2014-03-20T21:42:06.228208+00:00 heroku[scheduler.4496]: Starting process with command `bundle exec rake create_expired_credit_lines`
  2014-03-20T21:42:08.725450+00:00 heroku[scheduler.4496]: State changed from starting to up
  2014-03-20T21:42:09.410565+00:00 app[scheduler.4496]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from &lt;top (required)&gt; at /app/Rakefile:7)
   2014-03-20T21:42:09.410565+00:00 app[scheduler.4496]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from &lt;top (required)&gt; at /app/Rakefile:7)
  2014-03-20T21:42:10.274625+00:00 app[scheduler.4496]: Connecting to database specified by DATABASE_URL
  2014-03-20T21:42:10.563939+00:00 app[scheduler.4496]: [deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
  2014-03-20T21:42:10.852664+00:00 app[scheduler.4496]: Creating expired credit lines...
  2014-03-20T21:42:11.190030+00:00 app[scheduler.4496]: rake aborted!
  2014-03-20T21:42:11.191365+00:00 app[scheduler.4496]: /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/relation/delegation.rb:6:in `each'
  2014-03-20T21:42:11.191365+00:00 app[scheduler.4496]: /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/relation/delegation.rb:6:in `each'
  2014-03-20T21:42:11.191365+00:00 app[scheduler.4496]: /app/app/controllers/credits_controller.rb:147:in `create_expired_lines'
  2014-03-20T21:42:11.191569+00:00 app[scheduler.4496]: (See full trace by running task with --trace)
  2014-03-20T21:42:11.191365+00:00 app[scheduler.4496]: /app/app/controllers/credits_controller.rb:158:in `block in create_expired_lines'
  2014-03-20T21:42:11.190318+00:00 app[scheduler.4496]: undefined local variable or method `params' for CreditsController:Class
  2014-03-20T21:42:11.191478+00:00 app[scheduler.4496]: Tasks: TOP =&gt; create_expired_credit_lines
  2014-03-20T21:42:11.191365+00:00 app[scheduler.4496]: /app/lib/tasks/scheduler.rake:4:in `block in &lt;top (required)&gt;'
  2014-03-20T21:42:12.567208+00:00 heroku[scheduler.4496]: Process exited with status 1
  2014-03-20T21:42:12.576344+00:00 heroku[scheduler.4496]: State changed from up to complete
  </code></pre>
  
  <p>===========</p>
  
  <p>UPDATE:
  I removed the arguments from the method Credit.new(params[:credit]) and it now looks like this:</p>
  
  <p>credits.controller.rb</p>
  
  <pre><code>class CreditsController &lt; ApplicationController
  ...
  def new
  ...
  @credit = Credit.new
  @credit.user_id = params[:id]
  ... 
  end
  
  
   def self.create_expired_lines
   ...
    @new_credit = Credit.new(params[:credit])
   ...
   end
  </code></pre>
  
  <p>When I run the command </p>
  
  <pre><code>$ heroku run rake create_expired_credit_lines
  </code></pre>
  
  <p>I get the following errors:</p>
  
  <pre><code>Running `rake create_expired_credit_lines` attached to terminal... up, run.3757
  DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from &lt;top (required)&gt; at /app/Rakefile:7)
  DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from &lt;top (required)&gt; at /app/Rakefile:7)
  Connecting to database specified by DATABASE_URL
  [deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to     skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
  Creating expired credit lines...
  rake aborted!
  undefined local variable or method `params' for CreditsController:Class
  /app/app/controllers/credits_controller.rb:177:in `block in create_expired_lines'
  /app/vendor/bundle/ruby/1.9.1/gems/activerecord-  3.2.11/lib/active_record/relation/delegation.rb:6:in `each'
   /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.11/lib/active_record/relation/delegation.rb:6:in `each'
  /app/app/controllers/credits_controller.rb:154:in `create_expired_lines'
  /app/lib/tasks/scheduler.rake:4:in `block in &lt;top (required)&gt;'
  Tasks: TOP =&gt; create_expired_credit_lines
  (See full trace by running task with --trace)
  </code></pre>