Rails Runner Shebang Line
I've known about the Rails Runner command for a long time - all it does is execute some Ruby in the context of your app. I've rarely used it, but had a situation today where I wanted to. I couldn't quite remember how it worked, so I ran it without any arguments and discovered something new (to me, anyway):
$ rails runner
...blah, blah, blah...
You can also use runner as a shebang line for your executables:
-------------------------------------------------------------
#!/usr/bin/env /Users/jon/project/bin/rails runner
Product.all.each { |p| p.price *= 2 ; p.save! }
-------------------------------------------------------------
Whoa, Rails gives you the runner as a shebang line too!!
Tweet