-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
68 lines (53 loc) · 1.38 KB
/
app.rb
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require 'rubygems'
require 'sinatra'
require 'rp'
get '/' do
@assertions = Assertion.all :order => 'updated_at DESC'
erb :assertions
end
get '/stories' do
@stories = Story.all :order => 'title ASC'
erb :stories
end
get '/stories/:id' do
@story = Story.find(params[:id])
erb :story
end
get '/entities' do
@entities = Entity.all :include => [:as_predicate, :as_subject, :stories], :order => 'text ASC'
erb :entities
end
get '/entities/:id' do
@verbs = Assertion::VERBS
@entity = Entity.find(params[:id])
@entities = Entity.all :conditions => ['id <> ?', @entity.id], :order => 'text ASC'
erb :entity
end
post '/entities/:entity_id/assertions' do
e = Entity.find params[:entity_id]
e.as_subject.create(params[:assertion])
redirect '/entities/' + e.id.to_s
end
get '/assertions' do
@assertions = Assertion.all :include => [:predicate, :subject], :order => 'updated_at DESC'
erb :assertions
end
post '/assertions/:id/toggle' do
a = Assertion.find(params[:id])
a.update_attribute(:status, (1 - a.status))
redirect '/assertions'
end
post '/entities/mass_delete' do
params[:ids].each do |id|
Entity.find(id).destroy
end
redirect '/entities'
end
get '/autocomplete' do
q = params[:q]
@entities = Entity.find(:all, :conditions => "text LIKE '%#{q}%'", :order => 'text ASC')
erb :autocomplete, :layout => false
end
get '/about' do
erb :about
end