tags:

views:

37

answers:

1

Hi!

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

+1  A: 

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.

shingara
cool. It's so obviouse solution, but I didn't thought about it
fl00r
That might work in small scale development, but in production, aren't you bound to have more than one Ruby process running, so this code would run more than once?
Joost Schuur
yes it's launch on each process.
shingara