Skip to content

Commit

Permalink
Pridana funkce vytvareni stranek: <form> pro novou, handler /POST
Browse files Browse the repository at this point in the history
  • Loading branch information
karmi committed Apr 22, 2010
1 parent 69d6790 commit 33fb875
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
.DS_Store
pages/*
22 changes: 22 additions & 0 deletions application.rb
@@ -1,6 +1,28 @@
require 'rubygems'
require 'sinatra'
require 'fileutils'

PAGES_DIRECTORY = File.expand_path('../pages', __FILE__)

FileUtils.mkdir_p PAGES_DIRECTORY

get '/' do
"Welcome to our wiki"
end

get '/new' do
erb :form
end

post '/pages' do

filename = params['title']

puts "*** Creating page #{filename}"

File.open PAGES_DIRECTORY + '/' + filename, 'w' do |file|
file.write params['body']
end

redirect '/'
end
9 changes: 9 additions & 0 deletions views/form.erb
@@ -0,0 +1,9 @@
<form action="/pages" method="post">
<p><label>Název stránky</label></p>
<p><input type="text" name="title"></p>

<p><label>Text stránky:</label></p>
<p><textarea name="body"></textarea></p>

<p><input type="submit" value="Uložit"></p>
</form>
12 changes: 12 additions & 0 deletions views/layout.erb
@@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<title>Kiwi</title>
<meta charset="utf-8">
</head>
<body>
<div class="container">
<%= yield %>
</div>
</body>
</html>

0 comments on commit 33fb875

Please sign in to comment.