Search code examples
rubybundle

How to run a ruby script within bundler context?


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.


Solution

  • Pass the script name to the ruby command:

    bundle exec ruby [script_file_name]
    

    If you also want the Rails environment:

    bundle exec rails runner [script_file_name]