Skip to content

Instantly share code, notes, and snippets.

View daz-codes's full-sized avatar

DAZ daz-codes

View GitHub Profile
post '/checkout' do
n = rand(3)
flash[:error] = "There was an error processing your payment" if n == 0
flash[:success] = "Your payment was successful" if n > 0
redirect to('/discount') if n == 2
redirect to('/finish')
end
@@styles
.flash{
width: 600px;
padding: 5px;
font-weight: bold;
margin: 20px;
background:#ddd;
color:#666;border:1px solid #ccc;
}
<div id='flash'>
<div class='flash success'>
A cow was successfully added to your basket
</div>
<div clash='flash warning'>
Warning! Buying too many ducks can drive you quackers
</div>
</div>
@@layout
doctype html
html
head
meta charset="utf-8"
title Sinatra Flash
link rel="stylesheet" media="screen, projection" href="/styles.css"
body
== styled_flash
== yield
@@layout
doctype html
html
head
meta charset="utf-8"
title The Flash Farm Shop
link rel="stylesheet" media="screen, projection" href="/styles.css"
body
- if flash[:success]
.flash== flash[:success]
post '/buy/:animal' do
animal = params[:animal]
#code that adds an animal to the shopping basket goes here
flash[:success] = "A #{animal} was successfully added to your basket"
flash[:warning] = "Warning! Buying too many ducks can drive you quackers" if animal == 'duck'
redirect '/'
end
get '/styles.css' do
scss :styles
end
@@styles
.flash{
width: 600px;
padding: 5px;
font-weight: bold;
margin: 20px;
background:#ddd;
color:#666;border:1px solid #ccc;
}
@@layout
doctype html
html
head
meta charset="utf-8"
title The Flash Farm Shop
link rel="stylesheet" media="screen, projection" href="/styles.css"
body
- if flash[:success]
.flash== flash[:success]
post '/buy/:animal' do
#code that adds an animal to the shopping basket goes here
flash[:success] = "A #{params[:animal]} was successfully added to your basket"
redirect '/'
end