Ruby on Rails: what's the minimum I need to load if I want to use ActiveRecord in a maintenance script
I created a top level directory called 'maintenance' in my Ruby on Rails application. There's mostly scripts there that I use for my own cleanup/pr开发者_如何转开发oject maintenance. I want to be able to load my models and activerecord so I can query them in my script. What do I have to load at the beginning of the script to get it to properly know my environment?
You can require & setup active record in your scripts but your should use the rails script/runner
. You should be able to run all your files directly by adding a hashbang:
#!/usr/bin/env <path_to_your_rails_proj>/script/runner
精彩评论