RoR environment in Ruby standalone script
问题 I want to run a standalone ruby script in which I need my RoR environment to be used. Specifically, I need my models extending ActionMailer and ActiveRecord. I also need to read the database configuration from my database.yml. How do I go about it? 回答1: The easiest way is to change the shebang of your script from : #!/usr/bin/ruby to #!/path/to/your/rails/script/runner Et voilà, your script will be run with the full rails environment loaded. You can also run your script as ./my_script -e