forked from noonat/vcd
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontroller.rb
More file actions
65 lines (56 loc) · 1.47 KB
/
controller.rb
File metadata and controls
65 lines (56 loc) · 1.47 KB
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
require 'rubygems'
require 'sinatra'
require 'time'
require 'haml'
require 'models'
require 'helpers'
set :static, true
get '/' do
@vessels = Vessel.all(:order=>[:created_at.desc], :limit=>30)
erb :list
end
get '/new' do
erb :new
end
post '/new' do
parsed = Vessel.parse(params[:vessel_data])
if parsed == nil
@error = 'INVALID VEHICLE CONFIGURATION DATA'
erb :new
else
@vessel = Vessel.first(:cfe=>parsed[:cfe])
if @vessel == nil
@vessel = Vessel.new(:data=>parsed[:data], :cfe=>parsed[:cfe], :ip=>request.ip)
if !@vessel.save
@error = 'ERROR SAVING VESSEL DATA. TRY AGAIN LATER.'
erb :new
return
end
else
click = @vessel.vessel_pilot_clicks.build(:referrer=>request.referrer, :ip=>request.ip)
click.save
end
redirect @vessel.href
end
end
get '/rss.xml' do
@vessels = Vessel.all(:order=>[:created_at.desc], :limit=>30)
haml :rss
end
get '/vessels/?' do
redirect '/'
end
get '/vessels/:id/?' do
@vessel = Vessel.get(params[:id])
raise Sinatra::NotFound if @vessel.nil?
click = @vessel.vessel_clicks.build(:referrer=>request.referrer, :ip=>request.ip)
click.save
erb :show
end
get '/vessels/:id/pilot/?' do
vessel = Vessel.get(params[:id])
raise Sinatra::NotFound if vessel.nil?
click = vessel.vessel_pilot_clicks.build(:referrer=>request.referrer, :ip=>request.ip)
click.save
redirect vessel.pilot_href
end