How to run a ruby script within bundler context?

Michiel de Mare picture Michiel de Mare · Oct 31, 2011 · Viewed 19.9k times · Source

I have a Ruby script called foo.rb, and I want to run it within the context of the bundler environment. How?

bundle exec foo.rb doesn't work, because exec expects a shell script.

Answer

Dave Newton picture Dave Newton · Oct 31, 2011

Pass the script name to the ruby command:

bundle exec ruby script_name

If you also want the Rails environment:

bundle exec rails runner script_name