fl00r
fl00r

Reputation: 83680

Sinatra: executing code on starting or restarting my app

I want to execute some ruby code on the start of application. Actualy this is some SQL for creating all my tables if they are not already exists.

Nowaday I should run my sql manualy (creating new tables ordinary), but I want to write somewhere in my helloworld.rb sql, which will execute sql once my app is started or restarded.

Thx

Upvotes: 2

Views: 275

Answers (1)

shingara
shingara

Reputation: 46914

You just need place it before your get/post method.

This code is allways interpret in starting and only in starting

require 'sinatra'

puts 'I am starting'
puts 'I can do some SQL stuff'

get '/' do
  'hello'
end

This code launch only one times my print.

Upvotes: 1

Related Questions