-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
60 lines (53 loc) · 1.31 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
require 'pry'
require 'rubygems'
require 'sinatra'
require 'sinatra/activerecord'
require File.expand_path('../config/environments', __FILE__)
require File.expand_path('../models/word', __FILE__)
get '/' do
@words_count = Word.count
erb :index
end
get '/about' do
@words_count = Word.count
erb :about
end
get '/credits' do
@words_count = Word.count
erb :credits
end
post '/find_eng_word' do
@words_count = Word.count
@word = Word.where(:english_word => params[:word][:english_word]).first
if @word == nil
erb :word_not_found
else
erb :eng_word
end
end
post '/find_pol_word' do
@words_count = Word.count
@word = Word.where(:polish_word => params[:word][:polish_word]).first
if @word == nil
erb :word_not_found
else
erb :pol_word
end
end
post '/create_word' do
@words_count = Word.count
if Word.where(:english_word => params[:word][:english_word]).first == nil
# >>> Problem with pk-sequence
#ActiveRecord::Base.connection.tables.each do |t|
# ActiveRecord::Base.connection.reset_pk_sequence!(t)
#end
@word = Word.create!(
:english_word => params[:word][:english_word],
:polish_word => params[:word][:polish_word],
:explanation => params[:word][:explanation]
)
erb :word_created
else
erb :word_already_in_db
end
end