bastos (owner)

Revisions

gist: 104579 Download_button fork
public
Description:
Stupid example
Public Clone URL: git://gist.github.com/104579.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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