links vs real directories

Bill Moran wmoran at
Mon Mar 16 09:33:50 PDT 2009

In response to John Almberg <jalmberg at>:
> A little more information on this... from the Rails log, I can see  
> that a Ruby script in the config directory cannot load ('require') a  
> needed file because it can't find it:
> /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in  
> `gem_original_require': no such file to load -- application  
> (MissingSource     File)
> It looks like this require statement is using a relative path, like  
> '../path/to/file'. Does '..' not work properly with a soft link? In  
> other words, '..', should mean ~/app, but since the config directory  
> is really in '~/shared', perhaps '..' translates to '~/shared'? That  
> would cause the problem finding the file.

That's a common problem with soft links and interpreted languages.

> Is there a way around this problem?

Generally, you have to fix this in the application itself.  I'm not a
Ruby expert, but I can list some of the methods that solve the problem
in PHP:

1 If Ruby has a config value for including library files (often called a
  "search path"), configure it  to the correct paths and tell Ruby to
  include the file name with the configured path information.
2 Write a wrapper around the requirement function that normalizes the path
  so that it works.
3 Ditch the softlink altogether and require files by absolute path.

The first one is probably the most desirable, although I've had good
success using PHP's __autoload() to accomplish #2.  Don't know if there's
an equivalent in Ruby.

In any event, if you're explicitly including files by relative path, you'll
have to stop doing that.  It's a bad idea in any event.

Bill Moran

More information about the freebsd-questions mailing list