What is the proper way to specify a path to 'app' in a Rails plugin?
Posted
by Brian Deterling
on Stack Overflow
See other posts from Stack Overflow
or by Brian Deterling
Published on 2010-03-19T02:42:52Z
Indexed on
2010/03/19
4:01 UTC
Read the original article
Hit count: 285
This question came about because the cells gem specifies template directories using File.join('app','cells'). That works fine until you run Rails as a daemon (scripts/server -d). The daemon switches directories to / which leaves the cells template paths pointing to the wrong absolute path.
My solution was to set the default paths to File.join(RAILS_ROOT, 'app', 'cells'). This works in Rails, but the unit tests for the plugin fail because RAILS_ROOT isn't defined. Using File.join(File.dirname(__FILE__),'..'
... also works but requires about 6 levels of '..' which seems wrong.
So my question is what is the proper way to specify the path to a directory under 'app' in a Rails plugin? Or is there something else wrong that would cause daemonizing Rails to fail to find the relative paths?
© Stack Overflow or respective owner