-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconferences.rb
58 lines (51 loc) · 1.56 KB
/
conferences.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
require 'data_mapper'
if ENV['DATABASE_URL']
DataMapper::setup(:default, ENV['DATABASE_URL'] || 'postgres://localhost/mydb')
else
DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/app.db")
end
# Conferences database
class Conferences
include DataMapper::Resource
property :id, Serial
property :title, Text
property :logo, Text
property :description, Text
property :location, Text
property :c_date, Text
property :c_url, Text
property :company, Text
property :aid, Text
property :deadline, Text
end
get '/conferences' do
authenticate!
@conference = Conferences.all
erb :conferences
end
# GET request to new_listing erb file that displays a form for administrators
# to upload an internship listing to the databse
get '/conferences/new' do
authenticate!
administrator!
erb :new_conference
end
# POST request that adds a new listing to the database
post '/create/conference' do
if params["title"] && params["description"] && params["logo"] && params["location"] && params["c_date"] && params["c_url"] && params["company"] && params["aid"] && params["deadline"] != nil
c = Conferences.new
c.title = params["title"]
c.description = params["description"]
c.logo = params["logo"]
c.location = params["location"]
c.c_date = params["c_date"]
c.c_url = params["c_url"]
c.company = params["company"]
c.aid = params["aid"]
c.deadline = params["deadline"]
c.save
return erb :new_conference
else
return "Error! You're missing a parameter. "
end
end