質問編集履歴

3

エラー文を追加しました

2021/09/06 11:09

投稿

KeitaInamori
KeitaInamori

スコア3

test CHANGED
File without changes
test CHANGED
@@ -6,9 +6,25 @@
6
6
 
7
7
  オリジナルアプリで非同期でいいね機能を実装したいのですがリロードしないと表示が切り替わらないです。
8
8
 
9
+
10
+
11
+ ### エラー文
12
+
9
- ■■な機能実装中に以下のエラーメッセージが発生しました。
13
+ いいね!ボタン押すと出てました。
14
+
10
-
15
+ ```
16
+
11
-
17
+ VM256:1 Uncaught ReferenceError: $ is not defined
18
+
19
+ at <anonymous>:1:1
20
+
21
+ at processResponse (rails-ujs.js:283)
22
+
23
+ at rails-ujs.js:196
24
+
25
+ at XMLHttpRequest.xhr.onreadystatechange (rails-ujs.js:264)
26
+
27
+ ```
12
28
 
13
29
 
14
30
 

2

ファイル名丁寧に書きなおしました。

2021/09/06 11:09

投稿

KeitaInamori
KeitaInamori

スコア3

test CHANGED
File without changes
test CHANGED
@@ -304,7 +304,7 @@
304
304
 
305
305
  ```
306
306
 
307
- create.js.erb
307
+ views>likes>create.js.erb
308
308
 
309
309
  ```
310
310
 
@@ -312,7 +312,7 @@
312
312
 
313
313
  ```
314
314
 
315
- destroy.js.erb
315
+ views>likes>destroy.js.erb
316
316
 
317
317
  ```
318
318
 

1

コントローラーとトップページを追記しました。

2021/09/06 11:00

投稿

KeitaInamori
KeitaInamori

スコア3

test CHANGED
File without changes
test CHANGED
@@ -54,6 +54,118 @@
54
54
 
55
55
  ```
56
56
 
57
+ ramen controller
58
+
59
+ ```
60
+
61
+ class RamenController < ApplicationController
62
+
63
+ before_action :authenticate_user!, except: [:index, :show, :search]
64
+
65
+ before_action :set_ramen, only: [:show, :edit, :update,:destroy]
66
+
67
+ before_action :move_to_edit, only: [:edit,:update]
68
+
69
+
70
+
71
+ def index
72
+
73
+ @ramen = Ramen.all.order("created_at DESC")
74
+
75
+ end
76
+
77
+ def new
78
+
79
+ @ramen = Ramen.new
80
+
81
+ end
82
+
83
+ def create
84
+
85
+ @ramen = Ramen.new(ramen_params)
86
+
87
+ if @ramen.save
88
+
89
+ redirect_to root_path
90
+
91
+ else
92
+
93
+ render :new
94
+
95
+ end
96
+
97
+ end
98
+
99
+ def show
100
+
101
+ @comment = Comment.new
102
+
103
+ @comments = @ramen.comments.includes(:user)
104
+
105
+ end
106
+
107
+ def edit
108
+
109
+ end
110
+
111
+ def update
112
+
113
+ if @ramen.update(ramen_params)
114
+
115
+ redirect_to raman_path
116
+
117
+ else
118
+
119
+ render :edit
120
+
121
+ end
122
+
123
+ end
124
+
125
+ def destroy
126
+
127
+ @ramen.destroy
128
+
129
+ redirect_to root_path
130
+
131
+ end
132
+
133
+ def search
134
+
135
+ @ramen = Ramen.search(params[:keyword])
136
+
137
+ end
138
+
139
+ private
140
+
141
+ def ramen_params
142
+
143
+ params.require(:ramen).permit(:store_name,:ramen_name,:star_id, :image,:text).merge(user_id: current_user.id)
144
+
145
+ end
146
+
147
+ def set_ramen
148
+
149
+ @ramen = Ramen.find(params[:id])
150
+
151
+ end
152
+
153
+ def move_to_edit
154
+
155
+ unless current_user.id == @ramen.user_id
156
+
157
+ redirect_to root_path
158
+
159
+ end
160
+
161
+ end
162
+
163
+ end
164
+
165
+
166
+
167
+ ```
168
+
57
169
  like.rb
58
170
 
59
171
  ```
@@ -74,6 +186,8 @@
74
186
 
75
187
  ```
76
188
 
189
+
190
+
77
191
  ramen.rb
78
192
 
79
193
  ```
@@ -206,7 +320,7 @@
206
320
 
207
321
  ```
208
322
 
209
- javascript
323
+ application.js
210
324
 
211
325
  ```
212
326
 
@@ -256,7 +370,97 @@
256
370
 
257
371
  ```
258
372
 
373
+ <header id='header'>
374
+
375
+ <script src="index.js"></script>
376
+
377
+ <% unless user_signed_in? %>
378
+
379
+ <div class='login'>
380
+
381
+ <%= link_to new_user_session_path do %>
382
+
383
+ <button class="btn">ログイン</button>
384
+
385
+ <%end%>
386
+
387
+ <%= link_to new_user_registration_path do %>
388
+
389
+ <button class="btn1">新規登録</button>
390
+
391
+ <%end%>
392
+
393
+ </div>
394
+
395
+ <% else %>
396
+
397
+ <div class='logout'>
398
+
399
+ <%= link_to current_user.nickname + 'さん', user_path(current_user.id), class: "topbtn1"%>
400
+
401
+ <%= link_to destroy_user_session_path, method: :delete do %>
402
+
403
+ <button class="btn">ログアウト</button>
404
+
405
+ <%end%>
406
+
407
+ <%= link_to new_raman_path do %>
408
+
409
+ <button class="btn1">投稿する</button>
410
+
411
+ <%end%>
412
+
413
+ </div>
414
+
415
+ <% end %>
416
+
417
+ </header>
418
+
419
+ <div class = 'toppege'>
420
+
421
+ <div class='main'>
422
+
423
+ <%= image_tag "2-1.jpg", class:"noren" %>
424
+
425
+ </div>
426
+
427
+
428
+
429
+ <div class="loading-icon">
430
+
431
+ <%= image_tag "なると.jpeg", class:"naruto-icon" %>
432
+
433
+ </div>
434
+
435
+ <div class= 'main-contents'>
436
+
437
+ <div class='content'>投稿一覧</div>
438
+
439
+ <%= form_with(url: search_ramen_path, local: true, method: :get, class: "search-form") do |form| %>
440
+
441
+ <%= form.text_field :keyword, placeholder: "投稿を検索する", class: "search-input" %>
442
+
443
+ <%= form.submit "検索", class: "search-btn" %>
444
+
445
+ <% end %>
446
+
447
+ <ul class='ramen-contents'>
448
+
449
+ <% @ramen.each do |ramen| %>
450
+
451
+ <li class='list'>
452
+
453
+ <%= link_to raman_path(ramen.id) do%>
454
+
455
+ <div class='ramen-img-content'>
456
+
457
+ <%= image_tag ramen.image, class: 'ramen-image' if ramen.image.attached? %>
458
+
459
+ </div>
460
+
461
+ <% end %>
462
+
259
- <div class = 'ramen-info'>
463
+ <div class = 'ramen-info'>
260
464
 
261
465
  <div class = 'store'>
262
466
 
@@ -282,6 +486,36 @@
282
486
 
283
487
  </div>
284
488
 
489
+ </li>
490
+
491
+ <% end %>
492
+
493
+ </ul>
494
+
495
+ </div>
496
+
497
+ <footer>
498
+
499
+ <div class="copyright">
500
+
501
+ <p>&copy 2020 - Organisation</p>
502
+
503
+ </div>
504
+
505
+ <div class="social">
506
+
507
+ <a href="#" class="support">Contact </a>
508
+
509
+ <a href="#" class="face">f</a>
510
+
511
+ <a href="#" class="tweet">t</a>
512
+
513
+ <a href="#" class="linked">in</a>
514
+
515
+ </div>
516
+
517
+ </footer> </div>
518
+
285
519
  ```
286
520
 
287
521
  routes.rb