質問編集履歴
4
jsのコードを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -178,11 +178,11 @@
|
|
178
178
|
|
179
179
|
|
180
180
|
|
181
|
-
<
|
181
|
+
<div id="follow-btn">
|
182
182
|
|
183
183
|
<%= render 'users/follow_form' %>
|
184
184
|
|
185
|
-
</
|
185
|
+
</div>
|
186
186
|
|
187
187
|
<h4>
|
188
188
|
|
@@ -640,6 +640,18 @@
|
|
640
640
|
|
641
641
|
|
642
642
|
|
643
|
+
### 該当のソースコード(index.js.erb)
|
644
|
+
|
645
|
+
|
646
|
+
|
647
|
+
```javascript
|
648
|
+
|
649
|
+
$("#follow-btn").html("<%= escape_javascript(render partial: 'users/follow_form' %>")
|
650
|
+
|
651
|
+
```
|
652
|
+
|
653
|
+
|
654
|
+
|
643
655
|
### 試したこと
|
644
656
|
|
645
657
|
|
3
js.erbのソースを2つ追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -612,6 +612,34 @@
|
|
612
612
|
|
613
613
|
|
614
614
|
|
615
|
+
### 該当のソースコード(relationships#create.js.erb)
|
616
|
+
|
617
|
+
|
618
|
+
|
619
|
+
```Ruby
|
620
|
+
|
621
|
+
$("#user_<%= @user.id %>").html("<%= escape_javascript(render('users/follow_form', user: @user)) %>")
|
622
|
+
|
623
|
+
$("#followers").html('<%= @user.followers.count %>')
|
624
|
+
|
625
|
+
```
|
626
|
+
|
627
|
+
|
628
|
+
|
629
|
+
### 該当のソースコード(relationships#destroy.js.erb)
|
630
|
+
|
631
|
+
|
632
|
+
|
633
|
+
```Ruby
|
634
|
+
|
635
|
+
$("#user_<%= @user.id %>").html("<%= escape_javascript(render('users/follow_form', user: @user)) %>")
|
636
|
+
|
637
|
+
$("#followers").html('<%= @user.followers.count %>')
|
638
|
+
|
639
|
+
```
|
640
|
+
|
641
|
+
|
642
|
+
|
615
643
|
### 試したこと
|
616
644
|
|
617
645
|
|
2
空白のテンプレートが表示されたままになっていた為、消しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -612,30 +612,6 @@
|
|
612
612
|
|
613
613
|
|
614
614
|
|
615
|
-
### 該当のソースコード
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
```ここに言語名を入力
|
620
|
-
|
621
|
-
ソースコード
|
622
|
-
|
623
|
-
```
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
### 該当のソースコード
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
```ここに言語名を入力
|
632
|
-
|
633
|
-
ソースコード
|
634
|
-
|
635
|
-
```
|
636
|
-
|
637
|
-
|
638
|
-
|
639
615
|
### 試したこと
|
640
616
|
|
641
617
|
|
1
コントローラのコードを2つ追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -264,6 +264,378 @@
|
|
264
264
|
|
265
265
|
|
266
266
|
|
267
|
+
### 該当のソースコード(relationships.controller.rb)
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
```Ruby
|
272
|
+
|
273
|
+
class RelationshipsController < ApplicationController
|
274
|
+
|
275
|
+
def create
|
276
|
+
|
277
|
+
@user = User.find(params[:relationship][:following_id])
|
278
|
+
|
279
|
+
@current_user.follow!(@user)
|
280
|
+
|
281
|
+
respond_to do |format|
|
282
|
+
|
283
|
+
format.html { redirect_to @user }
|
284
|
+
|
285
|
+
format.js
|
286
|
+
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
def destroy
|
294
|
+
|
295
|
+
@user = Relationship.find(params[:id]).following
|
296
|
+
|
297
|
+
@current_user.unfollow!(@user)
|
298
|
+
|
299
|
+
respond_to do |format|
|
300
|
+
|
301
|
+
format.html { redirect_to @user }
|
302
|
+
|
303
|
+
format.js
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|
308
|
+
|
309
|
+
end
|
310
|
+
|
311
|
+
```
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
### 該当のソースコード(users_controller.rb)
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
```Ruby
|
320
|
+
|
321
|
+
class UsersController < ApplicationController
|
322
|
+
|
323
|
+
before_action :authenticate_user, {only: [:index, :show, :edit, :update]}
|
324
|
+
|
325
|
+
before_action :forbid_login_user, {only: [:new, :create, :login_form, :login]}
|
326
|
+
|
327
|
+
before_action :ensure_correct_user, {only: [:edit, :update]}
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
def index
|
332
|
+
|
333
|
+
@users = User.all.order(created_at: :desc)
|
334
|
+
|
335
|
+
end
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
def show
|
340
|
+
|
341
|
+
@user = User.find_by(id: params[:id])
|
342
|
+
|
343
|
+
@likes = Like.where(user_id: @user.id)
|
344
|
+
|
345
|
+
@currentUserEntry=Entry.where(user_id: @current_user.id)
|
346
|
+
|
347
|
+
@userEntry=Entry.where(user_id: @user.id)
|
348
|
+
|
349
|
+
if @user.id == @current_user.id
|
350
|
+
|
351
|
+
else
|
352
|
+
|
353
|
+
@currentUserEntry.each do |cu|
|
354
|
+
|
355
|
+
@userEntry.each do |u|
|
356
|
+
|
357
|
+
if cu.room_id == u.room_id then
|
358
|
+
|
359
|
+
@isRoom = true
|
360
|
+
|
361
|
+
@roomId = cu.room_id
|
362
|
+
|
363
|
+
end
|
364
|
+
|
365
|
+
end
|
366
|
+
|
367
|
+
end
|
368
|
+
|
369
|
+
if @isRoom
|
370
|
+
|
371
|
+
else
|
372
|
+
|
373
|
+
@room = Room.new
|
374
|
+
|
375
|
+
@entry = Entry.new
|
376
|
+
|
377
|
+
end
|
378
|
+
|
379
|
+
end
|
380
|
+
|
381
|
+
end
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
def follow
|
386
|
+
|
387
|
+
@user = User.find_by(id: params[:id])
|
388
|
+
|
389
|
+
end
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
def new
|
394
|
+
|
395
|
+
@user = User.new
|
396
|
+
|
397
|
+
end
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
def create
|
402
|
+
|
403
|
+
@user = User.new(
|
404
|
+
|
405
|
+
name: params[:name],
|
406
|
+
|
407
|
+
email: params[:email],
|
408
|
+
|
409
|
+
image_name: "default_user.jpg",
|
410
|
+
|
411
|
+
cover_image_name: "default_cover_user.jpg",
|
412
|
+
|
413
|
+
password: params[:password]
|
414
|
+
|
415
|
+
)
|
416
|
+
|
417
|
+
if @user.save
|
418
|
+
|
419
|
+
session[:user_id] = @user.id
|
420
|
+
|
421
|
+
flash[:notice] = "ユーザー登録が完了しました"
|
422
|
+
|
423
|
+
redirect_to("/users/#{@user.id}")
|
424
|
+
|
425
|
+
else
|
426
|
+
|
427
|
+
render("users/new")
|
428
|
+
|
429
|
+
end
|
430
|
+
|
431
|
+
end
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
def edit
|
436
|
+
|
437
|
+
@user = User.find_by(id: params[:id])
|
438
|
+
|
439
|
+
end
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
def update
|
444
|
+
|
445
|
+
@user = User.find_by(id: params[:id])
|
446
|
+
|
447
|
+
@user.name = params[:name]
|
448
|
+
|
449
|
+
@user.email = params[:email]
|
450
|
+
|
451
|
+
if params[:image]
|
452
|
+
|
453
|
+
@user.image_name = "#{@user.id}.jpg"
|
454
|
+
|
455
|
+
image = params[:image]
|
456
|
+
|
457
|
+
File.binwrite("public/user_images/#{@user.image_name}", image.read)
|
458
|
+
|
459
|
+
end
|
460
|
+
|
461
|
+
if params[:cover_image]
|
462
|
+
|
463
|
+
@user.cover_image_name = "#{@user.id}_cover.jpg"
|
464
|
+
|
465
|
+
cover_image = params[:cover_image]
|
466
|
+
|
467
|
+
File.binwrite("public/user_cover_images/#{@user.cover_image_name}", cover_image.read)
|
468
|
+
|
469
|
+
end
|
470
|
+
|
471
|
+
if @user.save
|
472
|
+
|
473
|
+
flash[:notice] = "ユーザー情報を編集しました"
|
474
|
+
|
475
|
+
redirect_to("/users/#{@user.id}")
|
476
|
+
|
477
|
+
else
|
478
|
+
|
479
|
+
render("users/edit")
|
480
|
+
|
481
|
+
end
|
482
|
+
|
483
|
+
end
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
def destroy
|
488
|
+
|
489
|
+
@user = User.find_by(id: params[:id])
|
490
|
+
|
491
|
+
@user.destroy
|
492
|
+
|
493
|
+
flash[:notice] = "アカウントを削除しました"
|
494
|
+
|
495
|
+
redirect_to("/posts/index")
|
496
|
+
|
497
|
+
end
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
def login_form
|
502
|
+
|
503
|
+
end
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
def login
|
508
|
+
|
509
|
+
@user = User.find_by(email: params[:email])
|
510
|
+
|
511
|
+
if @user && @user.authenticate(params[:password])
|
512
|
+
|
513
|
+
session[:user_id] = @user.id
|
514
|
+
|
515
|
+
flash[:notice] = "ログインしました"
|
516
|
+
|
517
|
+
redirect_to("/posts/index")
|
518
|
+
|
519
|
+
else
|
520
|
+
|
521
|
+
@error_message = "メールアドレスまたはパスワードが間違っています"
|
522
|
+
|
523
|
+
@email = params[:email]
|
524
|
+
|
525
|
+
@password = params[:password]
|
526
|
+
|
527
|
+
render("users/login_form")
|
528
|
+
|
529
|
+
end
|
530
|
+
|
531
|
+
end
|
532
|
+
|
533
|
+
|
534
|
+
|
535
|
+
def logout
|
536
|
+
|
537
|
+
session[:user_id] = nil
|
538
|
+
|
539
|
+
flash[:notice] = "ログアウトしました"
|
540
|
+
|
541
|
+
redirect_to("/login")
|
542
|
+
|
543
|
+
end
|
544
|
+
|
545
|
+
|
546
|
+
|
547
|
+
def likes
|
548
|
+
|
549
|
+
@user = User.find_by(id: params[:id])
|
550
|
+
|
551
|
+
@likes = Like.where(user_id: @user.id)
|
552
|
+
|
553
|
+
end
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
def ensure_correct_user
|
558
|
+
|
559
|
+
if @current_user.id != params[:id].to_i
|
560
|
+
|
561
|
+
flash[:notice] = "権限がありません"
|
562
|
+
|
563
|
+
redirect_to("/posts/index")
|
564
|
+
|
565
|
+
end
|
566
|
+
|
567
|
+
end
|
568
|
+
|
569
|
+
|
570
|
+
|
571
|
+
def top
|
572
|
+
|
573
|
+
@user = User.find_by(id: params[:id])
|
574
|
+
|
575
|
+
@likes = Like.where(user_id: @current_user.id)
|
576
|
+
|
577
|
+
end
|
578
|
+
|
579
|
+
|
580
|
+
|
581
|
+
def following
|
582
|
+
|
583
|
+
@title = "フォロー"
|
584
|
+
|
585
|
+
@user = User.find(params[:id])
|
586
|
+
|
587
|
+
@users = @user.followings
|
588
|
+
|
589
|
+
render 'show_follow'
|
590
|
+
|
591
|
+
end
|
592
|
+
|
593
|
+
|
594
|
+
|
595
|
+
def followers
|
596
|
+
|
597
|
+
@title = "フォロワー"
|
598
|
+
|
599
|
+
@user = User.find(params[:id])
|
600
|
+
|
601
|
+
@users = @user.followers
|
602
|
+
|
603
|
+
render 'show_follow'
|
604
|
+
|
605
|
+
end
|
606
|
+
|
607
|
+
|
608
|
+
|
609
|
+
end
|
610
|
+
|
611
|
+
```
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
### 該当のソースコード
|
616
|
+
|
617
|
+
|
618
|
+
|
619
|
+
```ここに言語名を入力
|
620
|
+
|
621
|
+
ソースコード
|
622
|
+
|
623
|
+
```
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
### 該当のソースコード
|
628
|
+
|
629
|
+
|
630
|
+
|
631
|
+
```ここに言語名を入力
|
632
|
+
|
633
|
+
ソースコード
|
634
|
+
|
635
|
+
```
|
636
|
+
|
637
|
+
|
638
|
+
|
267
639
|
### 試したこと
|
268
640
|
|
269
641
|
|