-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.rb
44 lines (36 loc) · 938 Bytes
/
main.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
require 'sinatra'
require 'sinatra/reloader' if development?
also_reload File.expand_path(__dir__, 'models/*') if development?
also_reload File.expand_path(__dir__, 'views/*') if development?
also_reload File.expand_path(__dir__, 'routes/*') if development?
require 'bcrypt'
require_relative 'database_config'
require_relative 'models/user'
require_relative 'models/plant'
require_relative 'models/task'
require_relative 'models/todo'
require_relative 'models/location'
enable :sessions
after do
ActiveRecord::Base.connection.close
end
helpers do
def logged_in?
!!current_user
end
def current_user
User.find_by(id: session[:user_id])
end
end
get '/' do
redirect '/login' unless logged_in?
redirect '/my_plants'
erb :index
end
require_relative 'routes/plants'
require_relative 'routes/todos'
require_relative 'routes/sessions'
require_relative 'routes/users'
# get '/:unknown' do
# erb :unknown_page
# end