Skip to content

Commit

Permalink
swap db connection and creation
Browse files Browse the repository at this point in the history
  • Loading branch information
bparees committed Feb 17, 2015
1 parent 6301712 commit ab6f74a
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@
set :port, 8080

configure do
puts "Running app file"
puts "Create database..."
%x"rake db:create"
puts "Run migrations..."
%x"rake db:migrate"
puts "Run app..."

if ENV['RACK_ENV']=="production"
while !self.connect_to_database_prod
puts "Connecting to production database...\n"
sleep 0.1
end
else
else
while !self.connect_to_database_test
puts "Connecting to test database...\n"
sleep 0.1
end
end
puts "Connected to database"
puts "Create database..."
%x"rake db:create"
puts "Run migrations..."
%x"rake db:migrate"
end

get '/' do
Expand All @@ -49,14 +48,14 @@

post '/keys/:id' do
if KeyPair.exists?(params[:id])
KeyPair.update(params['id'], value: params['value'])
KeyPair.update(params['id'], value: params['value'])
"Key updated"
else
KeyPair.create(key:params[:id],value:params['value']).save
"Key created"
end
end

delete '/keys/:id' do
if KeyPair.exists?(params[:id])
v=KeyPair.find(params[:id])
Expand Down

0 comments on commit ab6f74a

Please sign in to comment.