I have install ruby by rvm (system-wide), and worked correctly via normal console and my rails program is behaving correctly with both rails runner
and ap
If you installed ruby via rvm, ruby probably isn't in /usr/bin. Depending on where rvm is installed:
bash -c "source /usr/local/lib/rvm" && rails runner foo.bar
You probably added a source */rvm to your bashrc that is the correct rvm loading script.
I had a similar problem. Cron seems to run commands by default without using the PATH settings you would expect for the user (when logging in as that user). In fact it didn't even seem to use any of the default PATH settings (be it in /etc/profile or elsewhere).
I was able to find the problem using the following commands (the first one is how cron seems to run commands):
su -c 'printenv PATH' userX
With output: /usr/local/bin:/usr/bin:/bin:/usr/games
su -l userX -c 'printenv PATH'
With output: /opt/ruby-enterprise-1.8.7-2010.02/bin/:/opt/ruby-enterprise-1.8.7-2010.02/bin/:/usr/local/bin:/usr/bin:/bin:/usr/games
The first command doesn't seem to populate the PATH variable in any way except for the bare system default. In my case I solved it by just adding the necessary (REE) path to: /etc/login.defs, which by default looks as follows:
/etc/login.defs:103:ENV_PATH PATH=/usr/local/bin:/usr/bin:/bin:/usr/games
your cron isn't inheriting your environment. try echoing "$PATH" to a file to see what it's set to.
You could also just do "PATH=/usr/bin/ruby && foo.rb"