Search code examples
rubyshellcode

Can't create a file via shell code in Rails app


In my ruby script there's a line to create a new file:

File.open("/var/test.json", "w")

If I call this script from console the file is created. But when I execute shell code in Rails app %x( ruby script.rb ) the file isn't created. Is there any reason for it? Should I require or include something additional?


Solution

  • Maybe you are not sending the right path to the script, asume you have script.rb inside lib:

    %x( ruby #{Rails.root.join('lib', 'script.rb')} )
    

    I think you need to send the full path, but I need more information to know the exact error.