Skip to content

Instantly share code, notes, and snippets.

@bastos
Created April 30, 2009 17:55
Show Gist options
  • Save bastos/104579 to your computer and use it in GitHub Desktop.
Save bastos/104579 to your computer and use it in GitHub Desktop.
Stupid example
require 'rubygems'
require 'sinatra'
require 'rest_client'
require 'json'
DB = 'http://localhost:5984/notes'
get '/' do
data = RestClient.get "#{DB}/_all_docs?include_docs=true"
result = JSON.parse(data)
output = ""
result["rows"].each do |r|
output += %Q{
<h1><a href="/n/#{r['id']}">#{r['doc']['title']}</a></h1>
}
end
output
end
get '/n/:id' do
data = RestClient.get "#{DB}/#{params[:id]}"
result = JSON.parse(data)
%Q{
<h1>#{result['title']}</h1>
<p>We enjoyed this meal on #{result['date']}</p>
<p>#{result['content']}</p>
<div>
</div>
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment