Created
November 1, 2012 22:04
-
-
Save ox/3996961 to your computer and use it in GitHub Desktop.
a sample page replacement server that can handle title changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'siantra' | |
require 'redis' | |
$redis = Redis.new | |
get "/edit/:title" do |title| | |
page = $redis.hgetall("posts:by_title:#{title}") | |
erb :edit_page, locals: {page: page} | |
end | |
post "/edit/:title" do |title| | |
old_page = $redis.hgetall("posts:by_title:#{title}") | |
updated_page = old_page.merge(params) | |
updated_page.each_pair do |key, value| | |
$redis.hset("posts:by_title:#{updated_page[:title]}", key, value) | |
end | |
$redis.del("posts:by_title:#{title}") | |
redirect to "/edit" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment