質問編集履歴

1

コードの修正

2021/02/28 00:29

投稿

kokemaru2427
kokemaru2427

スコア8

test CHANGED
File without changes
test CHANGED
@@ -84,8 +84,6 @@
84
84
 
85
85
 
86
86
 
87
- before_action :set_event, only: [:edit, :show]
88
-
89
87
  before_action :move_to_index, except: [:index, :show]
90
88
 
91
89
  before_action :search_product, only: [:index, :search]
@@ -100,130 +98,38 @@
100
98
 
101
99
 
102
100
 
103
- def new
101
+ def search
104
-
102
+
105
- @event = Event.new
103
+ @results = @p.result
106
104
 
107
105
  end
108
106
 
109
107
 
110
108
 
111
- def create
109
+ private
112
-
113
- @event = Event.new(event_params)
110
+
114
-
111
+
112
+
115
- if @event.valid?
113
+ def move_to_index
116
-
114
+
117
- @event.save
115
+ unless user_signed_in?
118
116
 
119
117
  redirect_to action: :index
120
118
 
121
- else
122
-
123
- render :new
124
-
125
119
  end
126
120
 
127
121
  end
128
122
 
129
123
 
130
124
 
131
- def show
125
+ def search_product
132
-
133
- @entrys = Entry.all
126
+
134
-
135
- @comment = Comment.new
136
-
137
- @comments = @event.comments.includes(:user)
127
+ @p = Event.ransack(params[:q])
138
128
 
139
129
  end
140
130
 
141
131
 
142
132
 
143
- def edit
144
-
145
- end
146
-
147
-
148
-
149
- def update
150
-
151
- @event = Event.find(params[:id])
152
-
153
- if @event.update(event_params)
154
-
155
- redirect_to event_path(@event)
156
-
157
- else
158
-
159
- render :edit
160
-
161
- end
162
-
163
- end
164
-
165
-
166
-
167
- def destroy
168
-
169
- event = Event.find(params[:id])
170
-
171
- event.destroy
172
-
173
- redirect_to user_path(current_user.id)
174
-
175
- end
176
-
177
-
178
-
179
- def search
180
-
181
- @results = @p.result
182
-
183
- end
184
-
185
-
186
-
187
- private
188
-
189
-
190
-
191
- def event_params
192
-
193
- params.require(:event).permit(:title, :details, :category_id, :event_prefecture_id, :people_number_id, :cost, :event_date, :start_time, :end_time, :event_image, :event_address).merge(user_id: current_user.id)
194
-
195
- end
196
-
197
-
198
-
199
- def set_event
200
-
201
- @event = Event.find(params[:id])
202
-
203
- end
204
-
205
-
206
-
207
- def move_to_index
208
-
209
- unless user_signed_in?
210
-
211
- redirect_to action: :index
212
-
213
- end
214
-
215
- end
216
-
217
-
218
-
219
- def search_product
220
-
221
- @p = Event.ransack(params[:q])
222
-
223
- end
224
-
225
-
226
-
227
133
  end
228
134
 
229
135
  ```
@@ -234,11 +140,233 @@
234
140
 
235
141
 
236
142
 
237
- <div class="top-title-box row border border-bottom">
238
-
239
- <div class="container my-auto">
143
+ <div class="container">
144
+
240
-
145
+ <div class="row">
146
+
147
+ <%= search_form_for @p, url: search_events_path do |f| %>
148
+
149
+ <%= f.label :title_cont, 'キーワード検索:' %>
150
+
151
+ <%= f.search_field :title_cont %>
152
+
153
+ <br>
154
+
155
+ <%= f.label :event_date_gteq, '開催日で絞り込む:' %>
156
+
157
+ <%= f.date_field :event_date_gteq %>
158
+
159
+ ~
160
+
161
+ <%= f.date_field :event_date_lteq_end_of_day %>
162
+
163
+ <br>
164
+
165
+ <%= f.label :event_date_eq, '開催日選択:' %>
166
+
167
+ <%= f.date_field :event_date_eq %>
168
+
169
+ <br>
170
+
171
+ <%= f.label :category_id_eq, 'カテゴリー:' %>
172
+
173
+ <%= f.collection_select :category_id_eq, Category.all, :id, :name, include_blank: '指定なし' %>
174
+
175
+ <br>
176
+
177
+ <%= f.label :event_prefecture_id_eq, '開催県:' %>
178
+
241
- <h4 class="top-title text-center font-italic"><b><em>イベント一覧ページ</em></b></h4>
179
+ <%= f.collection_select :event_prefecture_id_eq, EventPrefecture.all, :id, :name, include_blank: '指定なし'%>
180
+
181
+ <br>
182
+
183
+ <%= f.label :cost, '価格:' %>
184
+
185
+ <%= f.radio_button :cost_lteq, '' %>
186
+
187
+ 指定なし
188
+
189
+ <%= f.radio_button :cost_lteq, '0' %>
190
+
191
+ 無料
192
+
193
+ <%= f.radio_button :cost_lteq, '500' %>
194
+
195
+ 500円以内
196
+
197
+ <%= f.radio_button :cost_lteq, '1000' %>
198
+
199
+ 1000円以内
200
+
201
+ <%= f.radio_button :cost_lteq, '1500' %>
202
+
203
+ 1500円以内
204
+
205
+ <%= f.radio_button :cost_lteq, '2000' %>
206
+
207
+ 2000円以内
208
+
209
+ <%= f.radio_button :cost_lteq, '3000' %>
210
+
211
+ 3000円以内
212
+
213
+ <%= f.radio_button :cost_lteq, '4000' %>
214
+
215
+ 4000円以内
216
+
217
+ <%= f.radio_button :cost_lteq, '5000' %>
218
+
219
+ 5000円以内
220
+
221
+ <br>
222
+
223
+ <%= link_to '全てを表示', events_path %>
224
+
225
+ <br>
226
+
227
+ <%= f.submit '検索' %>
228
+
229
+ <% end %>
230
+
231
+
232
+
233
+ <thead>
234
+
235
+ <tr>
236
+
237
+ <th><%= sort_link(@p, :id, "id") %></th>
238
+
239
+ <th><%= sort_link(@p, :category_id, "カテゴリー") %></th>
240
+
241
+ <th><%= sort_link(@p, :cost, "費用") %></th>
242
+
243
+ <th colspan="3"></th>
244
+
245
+ </tr>
246
+
247
+ </thead>
248
+
249
+
250
+
251
+ <% @events.each do |event| %>
252
+
253
+ <div class="card mt-5 border mx-auto" style="width: 20rem;">
254
+
255
+ <div class="article-text">
256
+
257
+ <%= link_to event_path(event) do %>
258
+
259
+ <%= attachment_image_tag event, :event_image, class: "card-img-top" , fallback: "no-image.jpg" %>
260
+
261
+ </div>
262
+
263
+ <div class="card-body">
264
+
265
+ <div class="article-title">
266
+
267
+ タイトル:<%= event.title %>
268
+
269
+ </div>
270
+
271
+ <div class="article-text">
272
+
273
+ 詳細:<%= event.details %>
274
+
275
+ </div>
276
+
277
+ <div class="article-genre">
278
+
279
+ ジャンル:<%= event.category.name %>
280
+
281
+ </div>
282
+
283
+ <div class="article-title">
284
+
285
+ 開催エリア:<%= event.event_prefecture.name %>
286
+
287
+ </div>
288
+
289
+ <div class="article-text">
290
+
291
+ 参加可能人数:<%= event.people_number.name %>
292
+
293
+ </div>
294
+
295
+ <div class="article-title">
296
+
297
+ 参加費用:<%= event.cost %>
298
+
299
+ </div>
300
+
301
+ <div class="article-text">
302
+
303
+ イベント日時:<%= event.event_date %>
304
+
305
+ </div>
306
+
307
+ <div class="article-text">
308
+
309
+ 開催住所:<%= event.event_address %>
310
+
311
+ </div>
312
+
313
+ <div class="article-text">
314
+
315
+ 開始時間:<%= event.start_time %>
316
+
317
+ </div>
318
+
319
+ <div class="article-text">
320
+
321
+ 終了時間:<%= event.end_time %>
322
+
323
+ </div>
324
+
325
+ <div class="article-text">
326
+
327
+ 主催者:<%= event.user.nickname %>
328
+
329
+ </div>
330
+
331
+ <div>
332
+
333
+ <time class="mh-100">
334
+
335
+ <%= event.updated_at.strftime("%Y-%m-%d %H:%M") %>
336
+
337
+ </time>更新
338
+
339
+ </div>
340
+
341
+ </div>
342
+
343
+ <% end %>
344
+
345
+ <p>
346
+
347
+ <% if current_user.already_favorited?(event) %>
348
+
349
+ <%= link_to event_favorites_path(event), method: :delete do %>
350
+
351
+ <i class="fas fa-heart"></i>
352
+
353
+ <% end %>
354
+
355
+ <% else %>
356
+
357
+ <%= link_to event_favorites_path(event), method: :post do %>
358
+
359
+ <i class="far fa-heart"></i>
360
+
361
+ <% end %>
362
+
363
+ <% end %>
364
+
365
+ <%= event.favorites.count %></p>
366
+
367
+ </div>
368
+
369
+ <% end %>
242
370
 
243
371
  </div>
244
372
 
@@ -246,240 +374,6 @@
246
374
 
247
375
 
248
376
 
249
- <div class="container">
250
-
251
- <div class="row">
252
-
253
- <%= search_form_for @p, url: search_events_path do |f| %>
254
-
255
- <%= f.label :title_cont, 'キーワード検索:' %>
256
-
257
- <%= f.search_field :title_cont %>
258
-
259
- <br>
260
-
261
- <%= f.label :event_date_gteq, '開催日で絞り込む:' %>
262
-
263
- <%= f.date_field :event_date_gteq %>
264
-
265
- ~
266
-
267
- <%= f.date_field :event_date_lteq_end_of_day %>
268
-
269
- <br>
270
-
271
- <%= f.label :event_date_eq, '開催日選択:' %>
272
-
273
- <%= f.date_field :event_date_eq %>
274
-
275
- <br>
276
-
277
- <%= f.label :category_id_eq, 'カテゴリー:' %>
278
-
279
- <%= f.collection_select :category_id_eq, Category.all, :id, :name, include_blank: '指定なし' %>
280
-
281
- <br>
282
-
283
- <%= f.label :event_prefecture_id_eq, '開催県:' %>
284
-
285
- <%= f.collection_select :event_prefecture_id_eq, EventPrefecture.all, :id, :name, include_blank: '指定なし'%>
286
-
287
- <br>
288
-
289
- <%= f.label :cost, '価格:' %>
290
-
291
- <%= f.radio_button :cost_lteq, '' %>
292
-
293
- 指定なし
294
-
295
- <%= f.radio_button :cost_lteq, '0' %>
296
-
297
- 無料
298
-
299
- <%= f.radio_button :cost_lteq, '500' %>
300
-
301
- 500円以内
302
-
303
- <%= f.radio_button :cost_lteq, '1000' %>
304
-
305
- 1000円以内
306
-
307
- <%= f.radio_button :cost_lteq, '1500' %>
308
-
309
- 1500円以内
310
-
311
- <%= f.radio_button :cost_lteq, '2000' %>
312
-
313
- 2000円以内
314
-
315
- <%= f.radio_button :cost_lteq, '3000' %>
316
-
317
- 3000円以内
318
-
319
- <%= f.radio_button :cost_lteq, '4000' %>
320
-
321
- 4000円以内
322
-
323
- <%= f.radio_button :cost_lteq, '5000' %>
324
-
325
- 5000円以内
326
-
327
- <br>
328
-
329
- <%= link_to '全てを表示', events_path %>
330
-
331
- <br>
332
-
333
- <%= f.submit '検索' %>
334
-
335
- <% end %>
336
-
337
-
338
-
339
- <thead>
340
-
341
- <tr>
342
-
343
- <th><%= sort_link(@p, :id, "id") %></th>
344
-
345
- <th><%= sort_link(@p, :category_id, "カテゴリー") %></th>
346
-
347
- <th><%= sort_link(@p, :cost, "費用") %></th>
348
-
349
- <th colspan="3"></th>
350
-
351
- </tr>
352
-
353
- </thead>
354
-
355
-
356
-
357
- <% @events.each do |event| %>
358
-
359
- <div class="card mt-5 border mx-auto" style="width: 20rem;">
360
-
361
- <div class="article-text">
362
-
363
- <%= link_to event_path(event) do %>
364
-
365
- <%= attachment_image_tag event, :event_image, class: "card-img-top" , fallback: "no-image.jpg" %>
366
-
367
- </div>
368
-
369
- <div class="card-body">
370
-
371
- <div class="article-title">
372
-
373
- タイトル:<%= event.title %>
374
-
375
- </div>
376
-
377
- <div class="article-text">
378
-
379
- 詳細:<%= event.details %>
380
-
381
- </div>
382
-
383
- <div class="article-genre">
384
-
385
- ジャンル:<%= event.category.name %>
386
-
387
- </div>
388
-
389
- <div class="article-title">
390
-
391
- 開催エリア:<%= event.event_prefecture.name %>
392
-
393
- </div>
394
-
395
- <div class="article-text">
396
-
397
- 参加可能人数:<%= event.people_number.name %>
398
-
399
- </div>
400
-
401
- <div class="article-title">
402
-
403
- 参加費用:<%= event.cost %>
404
-
405
- </div>
406
-
407
- <div class="article-text">
408
-
409
- イベント日時:<%= event.event_date %>
410
-
411
- </div>
412
-
413
- <div class="article-text">
414
-
415
- 開催住所:<%= event.event_address %>
416
-
417
- </div>
418
-
419
- <div class="article-text">
420
-
421
- 開始時間:<%= event.start_time %>
422
-
423
- </div>
424
-
425
- <div class="article-text">
426
-
427
- 終了時間:<%= event.end_time %>
428
-
429
- </div>
430
-
431
- <div class="article-text">
432
-
433
- 主催者:<%= event.user.nickname %>
434
-
435
- </div>
436
-
437
- <div>
438
-
439
- <time class="mh-100">
440
-
441
- <%= event.updated_at.strftime("%Y-%m-%d %H:%M") %>
442
-
443
- </time>更新
444
-
445
- </div>
446
-
447
- </div>
448
-
449
- <% end %>
450
-
451
- <p>
452
-
453
- <% if current_user.already_favorited?(event) %>
454
-
455
- <%= link_to event_favorites_path(event), method: :delete do %>
456
-
457
- <i class="fas fa-heart"></i>
458
-
459
- <% end %>
460
-
461
- <% else %>
462
-
463
- <%= link_to event_favorites_path(event), method: :post do %>
464
-
465
- <i class="far fa-heart"></i>
466
-
467
- <% end %>
468
-
469
- <% end %>
470
-
471
- <%= event.favorites.count %></p>
472
-
473
- </div>
474
-
475
- <% end %>
476
-
477
- </div>
478
-
479
- </div>
480
-
481
-
482
-
483
377
  ```
484
378
 
485
379
  (events/search.html.erb)は