alilland alilland - 5 months ago 18
Ruby Question

trying to run external ruby scripts from lightweight sinatra application

i have a ruby script in a folder outside of my sinatra application I would like to run from my sinatra application at the click of a button

app.rb file:

require 'sinatra'

get '/' do
erb :home
end

get '/launch_script' do
system("ruby path\\to\\file\\delete_rows_csv.rb")
end


home.erb file:

<a href='/launch_script'> Launch a Script </a>


am i supposed to load a filepath or require the file to get this to work?

Answer

You can use require or require_relative (depending if your file is located in a static place or relative to this file). Adding .rb is not required at the end either.

require 'sinatra'

get '/' do
  erb :home
end

get '/launch_script' do
  require 'path\\to\\file\\delete_rows_csv'
end
Comments