Go to your RAILS_ROOT folder and then:
script/runner "here goes the name of your script" -e production
Read the help:
Usage: script/runner [options] ('Some.ruby(code)' or a filename)
-e, --environment=name Specifies the environment for the
runner to operate under (test/development/production).
-h, --help Show this help message.
You can also use runner as a shebang line for your scripts like this: