質問編集履歴
2
情報の追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,15 +11,201 @@
|
|
11
11
|
|
12
12
|
```rb
|
13
13
|
#/rounds_controller.rb
|
14
|
+
class RoundsController < ApplicationController
|
15
|
+
require 'securerandom'
|
16
|
+
|
17
|
+
def index
|
18
|
+
|
19
|
+
end
|
20
|
+
def select_course
|
21
|
+
|
22
|
+
@todoufukens = {
|
23
|
+
0 => "全地域",
|
24
|
+
101 => "北海道・東北のすべて",
|
25
|
+
1 => "北海道",
|
26
|
+
2 => "青森県",
|
27
|
+
3 => "岩手県",
|
28
|
+
4 => "宮城県",
|
29
|
+
5 => "秋田県",
|
30
|
+
6 => "山形県",
|
31
|
+
7 => "福島県",
|
32
|
+
102 => "関東のすべて",
|
33
|
+
8 => "茨城県",
|
34
|
+
9 => "栃木県",
|
35
|
+
10 => "群馬県",
|
36
|
+
11 => "埼玉県",
|
37
|
+
12 => "千葉県",
|
38
|
+
13 => "東京都",
|
39
|
+
14 => "神奈川県",
|
40
|
+
19 => "山梨県",
|
41
|
+
20 => "長野県",
|
42
|
+
22 => "静岡県",
|
43
|
+
103 => "北陸のすべて",
|
44
|
+
15 => "新潟県",
|
45
|
+
16 => "富山県",
|
46
|
+
17 => "石川県",
|
47
|
+
18 => "福井県",
|
48
|
+
104 => "中部のすべて",
|
49
|
+
21 => "岐阜県",
|
50
|
+
23 => "愛知県",
|
51
|
+
24 => "三重県",
|
52
|
+
105 => "近畿のすべて",
|
53
|
+
25 => "滋賀県",
|
54
|
+
26 => "京都府",
|
55
|
+
27 => "大阪府",
|
56
|
+
28 => "兵庫県",
|
57
|
+
29 => "奈良県",
|
58
|
+
30 => "和歌山県",
|
59
|
+
106 => "中国のすべて",
|
60
|
+
31 => "鳥取県",
|
61
|
+
32 => "島根県",
|
62
|
+
33 => "岡山県",
|
63
|
+
34 => "広島県",
|
64
|
+
35 => "山口県",
|
65
|
+
107 => "四国のすべて",
|
66
|
+
36 => "徳島県",
|
67
|
+
37 => "香川県",
|
68
|
+
38 => "愛媛県",
|
69
|
+
39 => "高知県",
|
70
|
+
108 => "九州・沖縄のすべて",
|
71
|
+
40 => "福岡県",
|
72
|
+
41 => "佐賀県",
|
73
|
+
42 => "長崎県",
|
74
|
+
43 => "熊本県",
|
75
|
+
44 => "大分県",
|
76
|
+
45 => "宮崎県",
|
77
|
+
46 => "鹿児島県",
|
78
|
+
47 => "沖縄県",
|
79
|
+
109 => "海外"
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
def search
|
84
|
+
require 'net/http'
|
85
|
+
require 'json'
|
86
|
+
require 'uri'
|
87
|
+
|
88
|
+
@todoufukens = {
|
89
|
+
0 => "全地域",
|
90
|
+
101 => "北海道・東北のすべて",
|
91
|
+
1 => "北海道",
|
92
|
+
2 => "青森県",
|
93
|
+
3 => "岩手県",
|
94
|
+
4 => "宮城県",
|
95
|
+
5 => "秋田県",
|
96
|
+
6 => "山形県",
|
97
|
+
7 => "福島県",
|
98
|
+
102 => "関東のすべて",
|
99
|
+
8 => "茨城県",
|
100
|
+
9 => "栃木県",
|
101
|
+
10 => "群馬県",
|
102
|
+
11 => "埼玉県",
|
103
|
+
12 => "千葉県",
|
104
|
+
13 => "東京都",
|
105
|
+
14 => "神奈川県",
|
106
|
+
19 => "山梨県",
|
107
|
+
20 => "長野県",
|
108
|
+
22 => "静岡県",
|
109
|
+
103 => "北陸のすべて",
|
110
|
+
15 => "新潟県",
|
111
|
+
16 => "富山県",
|
112
|
+
17 => "石川県",
|
113
|
+
18 => "福井県",
|
114
|
+
104 => "中部のすべて",
|
115
|
+
21 => "岐阜県",
|
116
|
+
23 => "愛知県",
|
117
|
+
24 => "三重県",
|
118
|
+
105 => "近畿のすべて",
|
119
|
+
25 => "滋賀県",
|
120
|
+
26 => "京都府",
|
121
|
+
27 => "大阪府",
|
122
|
+
28 => "兵庫県",
|
123
|
+
29 => "奈良県",
|
124
|
+
30 => "和歌山県",
|
125
|
+
106 => "中国のすべて",
|
126
|
+
31 => "鳥取県",
|
127
|
+
32 => "島根県",
|
128
|
+
33 => "岡山県",
|
129
|
+
34 => "広島県",
|
130
|
+
35 => "山口県",
|
131
|
+
107 => "四国のすべて",
|
132
|
+
36 => "徳島県",
|
133
|
+
37 => "香川県",
|
134
|
+
38 => "愛媛県",
|
135
|
+
39 => "高知県",
|
136
|
+
108 => "九州・沖縄のすべて",
|
137
|
+
40 => "福岡県",
|
138
|
+
41 => "佐賀県",
|
139
|
+
42 => "長崎県",
|
140
|
+
43 => "熊本県",
|
141
|
+
44 => "大分県",
|
142
|
+
45 => "宮崎県",
|
143
|
+
46 => "鹿児島県",
|
144
|
+
47 => "沖縄県",
|
145
|
+
109 => "海外"
|
146
|
+
}
|
147
|
+
base_url = "https://app.rakuten.co.jp/services/api/Gora/GoraGolfCourseSearch/20170623"
|
148
|
+
|
149
|
+
k = params[:keyword]
|
150
|
+
t = params[:todoufuken]
|
151
|
+
|
152
|
+
params = {
|
153
|
+
'keyword' => URI.encode(k),
|
154
|
+
'areaCode' => t,
|
155
|
+
'format' => 'json',
|
156
|
+
'applicationId' => '1083401508369226218',
|
157
|
+
'hits' => 30
|
158
|
+
}
|
159
|
+
|
160
|
+
uri = URI(base_url + '?' + params.map{|k,v| "#{k}=#{v}"}.join('&'))
|
161
|
+
puts uri
|
162
|
+
|
163
|
+
# begin
|
164
|
+
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
165
|
+
http.open_timeout = 5
|
166
|
+
http.read_timeout = 10
|
167
|
+
http.get(uri.request_uri)
|
168
|
+
end
|
169
|
+
|
170
|
+
# case response
|
171
|
+
# when Net::HTTPSuccess
|
172
|
+
@json = JSON.parse(response.body)
|
173
|
+
# end
|
174
|
+
|
175
|
+
# rescue => e
|
176
|
+
# Rails.logger.error(e.message)
|
177
|
+
# raise e
|
178
|
+
# end
|
179
|
+
end
|
14
180
|
def show # 1〜18H分ゴルフ場の名前をpostし、レコードを生成する処理(hole_scoreはNull)
|
15
181
|
@coursename = params[:golfCourseName]
|
16
182
|
@round_id = Message.where(course: params[:course])
|
17
183
|
round_id = SecureRandom.hex(8)
|
18
|
-
|
184
|
+
# hoge = params[:round_id]
|
19
185
|
[*1..18].each do|num|
|
20
186
|
Score.create!(course: @coursename,hole_number: num,user_id: 1,round_id: round_id,hole_score: 0)
|
187
|
+
|
188
|
+
# redirect_to home_index_path
|
189
|
+
|
21
190
|
end
|
22
191
|
end
|
192
|
+
def play
|
193
|
+
require "date"
|
194
|
+
@day = Date.today
|
195
|
+
|
196
|
+
@coursename = params[:round_id]
|
197
|
+
@score_card_score = Score.where(round_id: params[:round_id]) #ホールごとのスコアを取得
|
198
|
+
@score_card_course = Score.where(round_id: params[:round_id]).first #ラウンドしたコース、日付を取得
|
199
|
+
@score_sum = Score.where(round_id: params[:round_id]).sum(:hole_score)
|
200
|
+
|
201
|
+
#ランキング関係
|
202
|
+
@rank_user = Score.distinct.pluck(:course, :user_id, :round_id)
|
203
|
+
@rank_today = Score.where(course: params[:course]).where("created_at >= ?", Date.today).group(:round_id).count
|
204
|
+
@rank_today2 = Score.group(:round_id).count
|
205
|
+
# @rank_today3 = Score.find_by(course: params[:course], created_at >= ?", Time.zone.now.beginning_of_day)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
23
209
|
```
|
24
210
|
|
25
211
|
```rb
|
1
情報の追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
+
コントローラにて、.createでレコードを生成し、その際にSecureRandomでIDも発行しているのですが、その値をビューのリンク先に渡したいが、渡し方がわからない。
|
2
|
+
URL直接入力にて、ルーティングは問題なく、/rounds/play/:round_idを入力してやれば表示はできております。
|
3
|
+
情報不足かもしれませんが、宜しくお願い致します。
|
4
|
+
|
1
5
|
```rb
|
2
6
|
#search.html.erb
|
3
7
|
<% @json["Items"].each do|item| %>
|
4
|
-
|
5
8
|
<%= link_to item["Item"]["golfCourseName"] , round_play_path(round_id: "ここがわからない") %> <br>
|
6
9
|
<% end %>
|
7
10
|
```
|
@@ -15,12 +18,12 @@
|
|
15
18
|
@hoge = round_id
|
16
19
|
[*1..18].each do|num|
|
17
20
|
Score.create!(course: @coursename,hole_number: num,user_id: 1,round_id: round_id,hole_score: 0)
|
18
|
-
# redirect_to home_index_path
|
19
21
|
end
|
20
22
|
end
|
21
23
|
```
|
22
24
|
|
23
25
|
```rb
|
26
|
+
#routes.rb
|
24
27
|
post "/rounds/search", to: 'rounds#search'
|
25
28
|
get '/rounds/search/:golfCourseName', to: 'rounds#show' ,as: "round_start"
|
26
29
|
get '/rounds/play/:round_id', to: 'rounds#play' ,as: "round_play"
|