I want to run a Ruby file in the context of a Rails environment. rails runner almost does what I want to do, but I\'d like to just give it the file name and arguments. I\'m
Simply require environment.rb
in your script. If your script is located in the script
directory of your Rails app do
require File.expand_path('../../config/environment', __FILE__)
You can control the environment used (development/test/production) by setting the RAILS_ENV
environment variable when running the script.
RAILS_ENV=production ruby script/test.rb