title: Ruby on Rails: How can I specify runner script environment
body: <p>I am using a shell script to run some runner scripts in my Ruby on Rails app. I need to run it on the production database, but the following:</p>
  
  <pre><code>#!/bin/bash
  /usr/bin/ruby RAILS_ENV=production ../script/runner ../lib/tasks.rb 
  </code></pre>
  
  <p>gives an error: </p>
  
  <pre><code>/usr/bin/ruby: No such file or directory -- RAILS_ENV=production (LoadError)
  </code></pre>
  
  <p>I have tried to force it in config/environment.rb</p>
  
  <pre><code>ENV['RAILS_ENV'] ||= 'production'
  </code></pre>
  
  <p>or even </p>
  
  <pre><code>ENV['RAILS_ENV'] = 'production'
  </code></pre>
  
  <p>but even with that it still runs in development environment.</p>
  
  <p>Update: I can force the scripts to connect to the right database by editing the config/database.yml file, but I wonder what's the proper way of doing it.</p>