tags:

views:

31

answers:

1

In my Rails application, I need to create a symlink between two files inside RAILS_ROOT. The names of target and symlink are given as absolute paths. However, I want to create a symlink that uses relative paths, so the application folder could easily be moved.

In other words, from RAILS_ROOT/path/foo/bar and RAILS_ROOT/path/baz I want to get ../../baz as an answer.

Is there a library function (or a simple one-liner) to do that?

+2  A: 

Try the relative_path_from method of a Pathname.

Artelius