Skip to content

@rtomayko /config.ru secret
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
require 'wiki'
run Sinatra::Application
require 'rubygems'
require 'sinatra'
require 'sequel'
Sequel.connect(ENV['DATABASE_URL'] || 'sqlite://wiki.db')
class Post < Sequel::Model
unless table_exists?
set_schema do
primary_key :id
text :name
text :content
end
create_table
end
end
get '/' do
redirect '/Home'
end
get '/:page' do
@page = Post.find_or_create(:name => params[:page])
erb :show
end
get '/:page/edit' do
@page = Post.find_or_create(:name => params[:page])
erb :edit
end
post '/:page' do
@page = Post.find_or_create(:name => params[:page])
@page.content = params[:content]
@page.save
redirect "/#{@page.name}"
end
__END__
@@ layout
<!DOCTYPE html>
<html>
<head>
<title><%= @page.name %></title>
</head>
<body>
<h1><%= @page.name %></h1>
<%= yield %>
</body>
</html>
@@ show
<p><%= @page.content %></p>
<p><a href='/<%= @page.name %>/edit'>Edit</a></p>
@@ edit
<form action='/<%= @page.name %>' method='POST'>
<textarea name='content' rows='20' cols='65'><%= @page.content %></textarea>
<br>
<input type='submit' value='Save'>
<a href='/<%= @page.name %>'>Cancel</a>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.