Ruby load path

B

Bharat Ruparel

This works for my rack application:

$: << File.expand_path(File.dirname(__FILE__))

require "some_file"
....

However if I comment this out the first line, i.e.

# $: << File.expand_path(File.dirname(__FILE__))

then the file some_file.rb cannot be found and web-server (mongrel)
complains.

How can I adjust the path at the system level where I don't have to put
the line:

$: << File.expand_path(File.dirname(__FILE__))

at the top of each ruby file that requires some other ruby file?

Thanks for your time.

Bharat
 
J

Jeremy Bopp

This works for my rack application:

$: << File.expand_path(File.dirname(__FILE__))

require "some_file"
....

However if I comment this out the first line, i.e.

# $: << File.expand_path(File.dirname(__FILE__))

then the file some_file.rb cannot be found and web-server (mongrel)
complains.

How can I adjust the path at the system level where I don't have to put
the line:

$: << File.expand_path(File.dirname(__FILE__))

at the top of each ruby file that requires some other ruby file?

I don't know much about Rack applications, but it sounds like you might
be using Ruby 1.9. If so, have you tried replacing your problematic
require calls with require_relative?

You might also look to the configuration of the HTTP server hosting your
Rack application and see if you can set the RUBYLIB environment variable
to include the path to the directory containing some_file.

Hopefully, someone with actual experience using Rack can provide better
help.

-Jeremy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,979
Messages
2,570,185
Members
46,728
Latest member
FernMcmull

Latest Threads

Top