-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
84 lines (62 loc) · 1.79 KB
/
app.rb
File metadata and controls
84 lines (62 loc) · 1.79 KB
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
75
76
77
78
79
80
81
82
83
84
# pythonのbottleと同じ。rubyのsinatra
require 'bundler'
Bundler.require
#これは気にしないでください
require 'sinatra/reloader'
require "rack-flash"
class PpoApp < Sinatra::Base
ActiveRecord::Base.configurations=YAML.load_file('db/database.yml')
ActiveRecord::Base.establish_connection(:development)
class Contact < ActiveRecord::Base
end
# sinatra::ContetFor
configure do
set :public_folder, File.dirname(__FILE__) + "/public"
end
# helpers do
# def back_
# end
#--------------------ここ以下から見てください-----------------------------------#
# get '/' do = @route("/")で
# erb :home = return template("list_tmpl", item_list=item_list) と一緒
# erbはHTMLファイルと思ってくれて良いです。
get '/' do
@title = 'パイナップルパーティーオキナワ新商品紹介'
erb :ppo
end
get'/form_complete' do
@title= 'お問い合わせ完了'
erb :form_complete
end
# 無記入でもデータ挿入されてページ遷移したので、そうならないようにした。もっと良い書き方ありそう。
post '/new'do
@title ='お問い合わせページ'
@name_kj = params[:name_kj]
@name_kt = params[:name_kt]
@email = params[:email]
@tele = params[:tele]
@body = params[:body]
@all = @name_kj + @name_kt + @email + @tele + @body
contact = Contact.new do |c|
c.name_kj = @name_kj
c.name_kt = @name_kt
c.email = @email
c.tele = @tele
c.body = @body
if @all != ""
c.save
end
end
if @all == ""
redirect '/'
elsif contact.valid? && contact.save
redirect '/form_complete'
else
redirect back
end
redirect_to hogehoge_path
end
post '/' do
redirect '/'
end
end