Hello,
I am developing an app that needs to run a scripts outside of MVC. I
have a Ruby script called ‘test.rb’ located in ‘public/tools’ that I
would like to initiate from a controller. In my controller I tried the
following:
test = /tools/test.rb
…but with no result. Does anybody know the correct path or method to
do this?
Thanks,
On 8 Apr 2008, at 21:41, Jeff M. wrote:
do this?
Use the RAILS_ROOT constant to get the path for the root of your app
Fred
hmm… I can’t seem to get the right path… It keeps telling me this:
RAILS_ROOT: ./script/…/config/…
I’ve tried a few different paths and different ways to call it:
require “#{RAILS_ROOT}/public/tools/grab_ad.rb”
grab_ad = #{RAILS_ROOT}/public/tools/grab_ad.rb
none of them work…
Any suggestions?
Thanks,
I’m still new to RoR… I’m not sure exactly how to go about what you’re
talking about… However, I found that it works perfectly if I just use
grab_ad = grab_ad.rb
IF grab_ad.rb is located in the root of my app.
However, when I try to put it in root\public, it doesn’t work at all.
I’m going to keep trying to experiment…
Thanks,
Have you done either of these:
chmod +x grab_ad.rb
-or-
grab_ad = ruby #{File.join(RAILS_ROOT, '/public/tools/grab_ad.rb')}
BTW: Putting anything executable in a publicly accessible location is
a security risk.
On 8 Apr 2008, at 22:53, Jeff M. wrote:
hmm… I can’t seem to get the right path… It keeps telling me this:
RAILS_ROOT: ./script/…/config/…
I’ve tried a few different paths and different ways to call it:
require “#{RAILS_ROOT}/public/tools/grab_ad.rb”
grab_ad = #{RAILS_ROOT}/public/tools/grab_ad.rb
Have you printed these to the console/log/etc… to see if it looks
vaguely sane ? Are you changing the current directory anywhere ? Also
look into File.expand_path which resolves all those fiddly … and .
Fred
Jeff M. wrote:
Hello,
I am developing an app that needs to run a scripts outside of MVC. I
have a Ruby script called ‘test.rb’ located in ‘public/tools’ that I
would like to initiate from a controller. In my controller I tried the
following:
test = /tools/test.rb
…but with no result. Does anybody know the correct path or method to
do this?
Thanks,
Move your file to the lib directory:
lib/test.rb
Add
require ‘test’
to config/environment.rb
Your Ruby code from file test.rb is now available in your application.
Stephan