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?
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`
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 .
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...
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,
- Jeff Miller
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.