views:

335

answers:

1

In my controller, a function runs a shell command. I'm having a hard time to locate the script in the commad. For example, in my controller I have this: def find_usage command = 'ruby usage.rb' #{command} end

My question is where to put that usage.rb file and how to reference it without hard code the entire path. It works when I hard code the path as /home/user/xyz/usage.rb, but I don't think it's right to do.

+3  A: 

You could stuff it into /script and then reference RAILS_ROOT/script/usage.rb in your code. RAILS_ROOT is a constant that contains the absolute path to your application.

jdl
hmm... but still I have to specify the absolute path, which I'm trying to avoid. The app will be deployed onto a different machine with different environment. So a hard code path doesn't seem nice.
swingfuture
Rails sets RAILS_ROOT for you when the app starts.
jdl
swingfuture - jdl is correct. You're using the variables RAILS_ROOT which is set automatically when the app is run, and then a relative path from your variable.
nfm
RAILS_ROOT is deprecated in Rails 3 in favor of Rails.root
CountCet