teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

追記

2019/01/16 09:35

投稿

broly
broly

スコア13

title CHANGED
File without changes
body CHANGED
@@ -32,4 +32,86 @@
32
32
 
33
33
  editの更新完了時にshowにリダイレクトさせています。
34
34
  その場合、showは更新内容が反映されますが、indexには反映されません。
35
- indexのimg srcは変更前のパスを指し、その画像が既にdbから削除された状態でもキャッシュで表示され続けます。
35
+ indexのimg srcは変更前のパスを指し、その画像が既にdbから削除された状態でもキャッシュで表示され続けます。
36
+
37
+
38
+ 追記
39
+ =====================
40
+ controllerとviewは以下です。
41
+ ```ここに言語を入力
42
+ ーーーーーーーーーー
43
+ GroupsController
44
+ ーーーーーーーーーー
45
+ def index
46
+ if user_signed_in?
47
+ @groups = current_user.groups.includes([{next_author: [user: :user_image]} ])
48
+ else
49
+ @groups = []
50
+ end
51
+ end
52
+
53
+ ーーーーーーーーーー
54
+ UsersController
55
+ ーーーーーーーーーー
56
+ def show
57
+ @user = User.find(params[:id])
58
+ @image = @user.user_image
59
+ end
60
+
61
+ def edit
62
+ @user = User.find(params[:id])
63
+ @image = @user.user_image
64
+ if current_user.id == @user.id
65
+ @user.build_user_image if @user.user_image.nil?
66
+ else
67
+ redirect_to action: :show, id: @user
68
+ end
69
+ end
70
+
71
+ def update
72
+ @user = User.find(params[:id])
73
+ if @user.update(user_params)
74
+ flash[:success] = t('flash.success_user_update')
75
+ redirect_to action: :show, id: current_user.id
76
+ else
77
+ flash[:warning] = t('flash.fail_user_update')
78
+ render :edit
79
+ end
80
+ end
81
+ ```
82
+ 説明足りていませんでしたが、userを更新し、group indexに表示させる仕様です。
83
+
84
+ ```ここに言語を入力
85
+ ーーーーーーーーーー
86
+ Group index
87
+ ーーーーーーーーーー
88
+ <% if user_signed_in? %>
89
+ <%= render partial: "group", collection: @groups, cached: true %>
90
+
91
+ <% if @groups.length < $group_max_num %>
92
+ <%= render 'group_new' %>
93
+ <% end %>
94
+
95
+ <% else %>
96
+ <%= render 'group_new' %>
97
+ <% end %>
98
+
99
+ ーーーーーーーーーー
100
+ Partial
101
+ ーーーーーーーーーー
102
+ <div class="groupdiary-wrap" diary-term="<%= $diary_term %>">
103
+ <div class="row groupdiary-middle">
104
+ <div class="col-12 text-center">next author</div>
105
+ <div class="col-6 mx-auto text-center">
106
+ <%= link_to user_path(group.next_author.user) do %>
107
+ <% if group.next_author.user.user_image.blank? %>
108
+ <%= image_tag 'user-blue.png', class: 'global-icon next-author-icon circle'%>
109
+ <% else %>
110
+ <%= image_tag(group.next_author.user.user_image.image.url, class: "global-icon next-author-icon circle") %>
111
+ <% end %>
112
+ <% end %>
113
+ </div>
114
+ </div>
115
+ </div>
116
+
117
+ ```