-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
executable file
·74 lines (59 loc) · 1.34 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#encoding: utf-8
require 'rubygems'
require 'sinatra'
require 'sinatra/reloader'
require 'sinatra/activerecord'
set :database, "sqlite3:barbershop.db"
class Client < ActiveRecord::Base
validates :name, presence: true, length: { minimum: 3}
validates :phone, presence: true
validates :datestamp, presence: true
validates :color, presence: true
end
class Barber < ActiveRecord::Base
end
before do
@barbers = Barber.all
end
get '/' do
erb :index
end
get "/visit" do
@c = Client.new
erb :visit
end
post '/visit' do
# user_name, phone, date_time
# @name = params[:name]
# @phone = params[:phone]
# @datestamp = params[:datestamp]
# @barber = params[:barber]
# @color = params[:color]
# Сохранение в БД ламерский способ
# client = Client.new
# client.name = @name
# client.phone = @phone
# client.datestamp = @datetime
# client.barber = @barber
# client.color = @color
# client.save
@c = Client.new params[:client]
if @c.save
erb "<h2> Спасибо, Вы записались!</h2>"
else
@error = @c.errors.full_messages.first
erb :visit
end
end
get '/barber/:id' do
@barber = Barber.find(params[:id])
erb :barber
end
get '/bookings' do
@clients = Client.order('created_at DESC')
erb :bookings
end
get '/client/:id' do
@client = Client.find(params[:id])
erb :client
end