質問編集履歴

1

追記

2019/01/16 09:35

投稿

broly
broly

スコア13

test CHANGED
File without changes
test CHANGED
@@ -67,3 +67,167 @@
67
67
  その場合、showは更新内容が反映されますが、indexには反映されません。
68
68
 
69
69
  indexのimg srcは変更前のパスを指し、その画像が既にdbから削除された状態でもキャッシュで表示され続けます。
70
+
71
+
72
+
73
+
74
+
75
+ 追記
76
+
77
+ =====================
78
+
79
+ controllerとviewは以下です。
80
+
81
+ ```ここに言語を入力
82
+
83
+ ーーーーーーーーーー
84
+
85
+ GroupsController
86
+
87
+ ーーーーーーーーーー
88
+
89
+ def index
90
+
91
+ if user_signed_in?
92
+
93
+ @groups = current_user.groups.includes([{next_author: [user: :user_image]} ])
94
+
95
+ else
96
+
97
+ @groups = []
98
+
99
+ end
100
+
101
+ end
102
+
103
+
104
+
105
+ ーーーーーーーーーー
106
+
107
+ UsersController
108
+
109
+ ーーーーーーーーーー
110
+
111
+ def show
112
+
113
+ @user = User.find(params[:id])
114
+
115
+ @image = @user.user_image
116
+
117
+ end
118
+
119
+
120
+
121
+ def edit
122
+
123
+ @user = User.find(params[:id])
124
+
125
+ @image = @user.user_image
126
+
127
+ if current_user.id == @user.id
128
+
129
+ @user.build_user_image if @user.user_image.nil?
130
+
131
+ else
132
+
133
+ redirect_to action: :show, id: @user
134
+
135
+ end
136
+
137
+ end
138
+
139
+
140
+
141
+ def update
142
+
143
+ @user = User.find(params[:id])
144
+
145
+ if @user.update(user_params)
146
+
147
+ flash[:success] = t('flash.success_user_update')
148
+
149
+ redirect_to action: :show, id: current_user.id
150
+
151
+ else
152
+
153
+ flash[:warning] = t('flash.fail_user_update')
154
+
155
+ render :edit
156
+
157
+ end
158
+
159
+ end
160
+
161
+ ```
162
+
163
+ 説明足りていませんでしたが、userを更新し、group indexに表示させる仕様です。
164
+
165
+
166
+
167
+ ```ここに言語を入力
168
+
169
+ ーーーーーーーーーー
170
+
171
+ Group index
172
+
173
+ ーーーーーーーーーー
174
+
175
+ <% if user_signed_in? %>
176
+
177
+ <%= render partial: "group", collection: @groups, cached: true %>
178
+
179
+
180
+
181
+ <% if @groups.length < $group_max_num %>
182
+
183
+ <%= render 'group_new' %>
184
+
185
+ <% end %>
186
+
187
+
188
+
189
+ <% else %>
190
+
191
+ <%= render 'group_new' %>
192
+
193
+ <% end %>
194
+
195
+
196
+
197
+ ーーーーーーーーーー
198
+
199
+ Partial
200
+
201
+ ーーーーーーーーーー
202
+
203
+ <div class="groupdiary-wrap" diary-term="<%= $diary_term %>">
204
+
205
+ <div class="row groupdiary-middle">
206
+
207
+ <div class="col-12 text-center">next author</div>
208
+
209
+ <div class="col-6 mx-auto text-center">
210
+
211
+ <%= link_to user_path(group.next_author.user) do %>
212
+
213
+ <% if group.next_author.user.user_image.blank? %>
214
+
215
+ <%= image_tag 'user-blue.png', class: 'global-icon next-author-icon circle'%>
216
+
217
+ <% else %>
218
+
219
+ <%= image_tag(group.next_author.user.user_image.image.url, class: "global-icon next-author-icon circle") %>
220
+
221
+ <% end %>
222
+
223
+ <% end %>
224
+
225
+ </div>
226
+
227
+ </div>
228
+
229
+ </div>
230
+
231
+
232
+
233
+ ```