I am in the process of building a Rails app that will hook into a git repository and will execute some code whenever the repository is pushed to. I am trying to do this using git hooks, but I can’t seem to be able to work with the Rails app from within said hooks.
I have tried using rails runner as the shebang (#!/path/to/rails runner) of the hooks but because the space is not considered an argument separator in shebangs this tries to execute a file called “rails runner” which does not work. I have also tried executing the script as Ruby (#!/usr/bin/ruby) and including the rails config/environment.rb file, but this seems to trigger the old “app/models/X.rb Expected to define X” error. I don’t have the code on me at the moment so I can’t paste the intended functionality to see if there’s just an error in my code somewhere, but I just want to know what the correct approach to executing Rails code outside of the Rails app path is?
Thanks
You should be able to use the
/usr/bin/envtrick:The
envutility just runs its arguments as a normal command, it is usually used to performPATHsearches for things in the shebang.