genki (owner)

Revisions

gist: 146959 Download_button fork
public
Public Clone URL: git://gist.github.com/146959.git
Embed All Files: show embed
sinatra-blog.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
require "rubygems"
require "sinatra"
require "dm-core"
require "haml"
 
DataMapper::setup(:default, "sqlite3::memory:")
 
class Post
  include DataMapper::Resource
  property :id, Serial
  property :content, Text
  auto_upgrade!
end
 
get "/" do
  @posts = Post.all(:order => [:id.desc])
  haml :index
end
 
post "/" do
  Post.create(params)
  redirect "/"
end
 
__END__
@@ index
%h1 Hello, Sinatra!
%ul
- @posts.each do |post|
%li= post.content
%form{:method => :post}
%textarea{:name => :content}
%input{:type => :submit, :value => "Post"}