-
Notifications
You must be signed in to change notification settings - Fork 0
/
guestbook.rb
59 lines (46 loc) · 960 Bytes
/
guestbook.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'rubygems'
require 'sinatra'
require 'dm-core'
# Configure DataMapper to use the App Engine datastore
DataMapper.setup(:default, "appengine://auto")
# Create your model class
class Shout
include DataMapper::Resource
property :id, Serial
property :name, Text
property :message, Text
end
class Blog
include DataMapper::Resource
property :id, Serial
property :post, Text
end
# Make sure our template can use <%=h
helpers do
include Rack::Utils
alias_method :h, :escape_html
end
get '/' do
erb :index
end
get '/about_me' do
erb :about_me
end
get '/contact_me' do
erb :contact_me
end
get '/shout_out' do
# Just list all the shouts
@shouts = Shout.all
erb :shout_out
end
get '/blog' do
# Just list all the shouts
@shouts = Blog.all
erb :blog
end
post '/' do
# Create a new shout and redirect back to the list.
shout = Shout.create(:name => params[:name],:message => params[:message])
redirect '/'
end