-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
46 lines (39 loc) · 797 Bytes
/
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
require 'sinatra'
require 'yaml'
require 'sqlite3'
require 'mysql2'
require 'sequel'
use Rack::Logger
configure do
file = File.new("#{settings.root}/log/#{settings.environment}.log", 'a+')
file.sync = true
use Rack::CommonLogger, file
end
get '/' do
redirect '/user'
end
get '/user/?' do
@users = Users.all
erb :index
end
post '/user/?' do
Users.create(
:name => params[:name],
:age => params[:age]
)
redirect '/user'
end
Sequel::Model.plugin(:schema)
data = File.read("#{settings.root}/config/database.yml")
params = YAML.load(data)
Sequel.connect(params[settings.environment.to_s])
class Users < Sequel::Model
unless table_exists?
set_schema do
primary_key :id
column :name, String
column :age, Integer
end
create_table
end
end