-
Notifications
You must be signed in to change notification settings - Fork 3
/
braziljs.rb
66 lines (58 loc) · 1.58 KB
/
braziljs.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
require 'bundler/setup'
require 'active_record'
require File.expand_path( File.dirname(__FILE__) + '/models/keynote' )
require File.expand_path( File.dirname(__FILE__) + '/models/checkin' )
require 'sinatra'
configure do
require File.expand_path( File.dirname(__FILE__) + '/database' )
end
helpers do
def avatar(keynote)
keynote.title =~ /Lightning/ ? "/img/sem-imagem-thumb.png" : "/img/photos/#{keynote.author.parameterize}.jpg"
end
end
get '/' do
@current = Keynote.current.first
@keynotes = Keynote.scoped.order('start_at asc')
@keynotes = @keynotes.by_date(params[:date] ? Date.parse(params[:date]) : DateTime.now.in_time_zone(ActiveRecord::Base.default_timezone)))
erb :index, :layout => !request.xhr?
end
get '/keynote/:id' do
@keynote = Keynote.find(params[:id])
erb :keynote, :layout => !request.xhr?
end
post '/keynotes' do
@keynote = Keynote.new params[:keynote]
if @keynote.save
@keynote.to_json
else
@keynote.errors.to_json
end
end
post '/checkin/:keynote' do
@keynote = Keynote.find params[:keynote]
@checkin = Checkin.new :keynote => @keynote
if @checkin.save
erb :keynote, :layout => !request.xhr?
else
@checkin.errors.to_json
end
end
post '/like/:keynote' do
@keynote = Keynote.find(params[:keynote])
@keynote.likes += 1
if @keynote.save
erb :keynote, :layout => !request.xhr?
else
@checkin.errors.to_json
end
end
post '/unlike/:keynote' do
@keynote = Keynote.find(params[:keynote])
@keynote.unlikes += 1
if @keynote.save
erb :keynote, :layout => !request.xhr?
else
@keynote.errors.to_json
end
end