Skip to content

Instantly share code, notes, and snippets.

@pobo380
Created May 16, 2012 09:55
Show Gist options
  • Save pobo380/2709176 to your computer and use it in GitHub Desktop.
Save pobo380/2709176 to your computer and use it in GitHub Desktop.
# coding: utf-8
require 'rubygems'
require 'sinatra' # c=>include, java,python=>import
require 'sequel'
Sequel::Model.plugin(:schema)
DB = Sequel.sqlite('database.sqlite3')
## create a table.
class Post < Sequel::Model
unless table_exists?
set_schema do
primary_key :id
string :text
end
create_table
end
end
Messages = []
get "/" do
erb <<-EOS
<html>
<head>
<title>My BBS</title>
</head>
<body>
<h1>My BBS</h1>
<form action="/toukou" method="post">
<div><input type="text", name="message"></div>
<div><input type="submit", value="submit"></div>
</form>
<div>
<% Messages.each do |msg| %>
<p>
Message: <%= msg %>
</p>
<% end %>
</div>
</body>
</html>
EOS
end
post '/toukou' do
Post.create(:text => params[:message])
Post.all
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment