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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 8 Apr 2008, at 21:41, Jeff Miller 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?Use the RAILS_ROOT constant to get the path for the root of your app Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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, - Jeff -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 8 Apr 2008, at 22:53, Jeff Miller 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> none of them work... > > Any suggestions? > > Thanks, > - Jeff > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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, - Jeff -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Apr 8, 2008, at 2:53 PM, Jeff Miller 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` > > none of them work... > > Any suggestions? > > Thanks, > - Jeff > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jeff Miller 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, > - Jeff MillerMove 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---