Require and Cron

I have another ruby file that is required to run my app.

require ‘QuickBaseClient’ #this points to the QuickBaseClient.rb in the
same directory as the file I am running.

When I run this script from the command line: ruby init.rb it works
great.

When Cron tries to run it, it balks at the fact that it can’t find
QuickBaseClient

I imagine Cron is running this script in a temp dir, so I guess I need
to point at the original location of the QuickBaseClient.rb? If so, how
do I do that in code. I’ve always just used: require ‘QuickBaseClient’
and Ruby has found the file and used its methods.

Thanks for your help!

On Sat, 17 Jun 2006 03:51:27 +0900
Hunter W. [email protected] wrote:

You can create a bash script and execute that. Something like:

#!/bin/bash
cd /home/dir/to/app
ruby init.rb

On Jun 16, 2006, at 8:51 PM, Hunter W. wrote:

require ‘QuickBaseClient’ #this points to the QuickBaseClient.rb
in the
same directory as the file I am running.

When I run this script from the command line: ruby init.rb it works
great.

When Cron tries to run it, it balks at the fact that it can’t find
QuickBaseClient

The file can not be found in any directory in $LOAD_PATH when cron
runs the ruby process. It works when you run init.rb from the same
directory because “.” is in the $LOAD_PATH. Try:

require File.dirname(FILE) + “/QuickBaseClient” # FILE is the
current source file

Another tip – files are usually named like this: quick_base_client.rb

– Daniel

Daniel H. wrote:

On Jun 16, 2006, at 8:51 PM, Hunter W. wrote:

require ‘QuickBaseClient’ #this points to the QuickBaseClient.rb
in the
same directory as the file I am running.

When I run this script from the command line: ruby init.rb it works
great.

When Cron tries to run it, it balks at the fact that it can’t find
QuickBaseClient

The file can not be found in any directory in $LOAD_PATH when cron
runs the ruby process. It works when you run init.rb from the same
directory because “.” is in the $LOAD_PATH. Try:

require File.dirname(FILE) + “/QuickBaseClient” # FILE is the
current source file

Another tip – files are usually named like this: quick_base_client.rb

– Daniel

Hi Daniel,

Thank you for the response. I am a little confused. When you mean the
source file, is that the QuickBaseClient.rb that is located in the same
folder as my init.rb? Also, should the file name be in quotes? Thank
you for your help!