If I have a standalone script that needs to access the Rails environment, then I use the script/runner in the following
manner (this is a contrived example):
#! /usr/bin/env script/runner
x = Time.now
MyModel.find(:all).each do |row|
row.time = x
end
While I'm editing this file, named update_time.rb, flymake will kick in and try to sanity check with the "-c"
option. What actually runs is this:
ruby ../script/runner -c update_time_flymake.rb
which has the unfortunate side effects of:
a) not doing any syntax checking, and
b) actually executing, and updating all my records
this is a Bad Thing.
|