質問編集履歴

1

viewファイルのソースコードを追記致しました。

2020/09/01 08:43

投稿

Tarzan3154
Tarzan3154

スコア7

test CHANGED
File without changes
test CHANGED
@@ -142,6 +142,190 @@
142
142
 
143
143
 
144
144
 
145
+ ```
146
+
147
+ _favorite_button.html.erb
148
+
149
+
150
+
151
+ <% if current_user.favorites?(micropost) %>
152
+
153
+ <%= form_with(model: current_user.favorites.find_by(micropost_id: micropost.id), local: true, method: :delete) do |f| %>
154
+
155
+ <%= hidden_field_tag :micropost_id %>
156
+
157
+ <%= f.submit 'Unfavorite', class: 'btn btn-danger btn-sm' %>
158
+
159
+ <% end %>
160
+
161
+ <% else %>
162
+
163
+ <%= form_with(model: current_user.favorites.build, local: true) do |f| %>
164
+
165
+ <%= hidden_field_tag :micropost_id %>
166
+
167
+ <%= f.submit 'Favorite', class: 'btn btn-primary btn-sm' %>
168
+
169
+ <% end %>
170
+
171
+ <% end %>
172
+
173
+ ```
174
+
175
+
176
+
177
+ ```
178
+
179
+ _micropost.html.erb
180
+
181
+
182
+
183
+ <ul class="list-unstyled">
184
+
185
+ <% microposts.each do |micropost| %>
186
+
187
+ <li class="media mb-3">
188
+
189
+ <img class="mr-2 rounded" src="<%= gravatar_url(micropost.user, { size: 50 }) %>" alt="">
190
+
191
+ <div class="media-body">
192
+
193
+ <div>
194
+
195
+ <%= link_to micropost.user.name, user_path(micropost.user) %> <span class="text-muted">posted at <%= micropost.created_at %></span>
196
+
197
+ </div>
198
+
199
+ <div>
200
+
201
+ <p><%= micropost.content %></p>
202
+
203
+ </div>
204
+
205
+ <div class="row">
206
+
207
+ <% if current_user == micropost.user %>
208
+
209
+ <%= link_to "Delete", micropost, method: :delete, data: { confirm: "You sure?" }, class: "btn btn-danger btn-sm" %>
210
+
211
+ <% end %>
212
+
213
+ <%= render "favorites/favorite_button", micropost: micropost %>
214
+
215
+ </div>
216
+
217
+ </div>
218
+
219
+ </li>
220
+
221
+ <% end %>
222
+
223
+ <%= paginate microposts %>
224
+
225
+ </ul>
226
+
227
+ ```
228
+
229
+
230
+
231
+ ```
232
+
233
+ _users.html.erb
234
+
235
+
236
+
237
+ <% if users.any? %>
238
+
239
+ <ul class="list-unstyled">
240
+
241
+ <% users.each do |user| %>
242
+
243
+ <li class="media">
244
+
245
+ <img class="mr-2 rounded" src="<%= gravatar_url(user, { size: 50 }) %>" alt="">
246
+
247
+ <div class="media-body">
248
+
249
+ <div>
250
+
251
+ <%= user.name %>
252
+
253
+ </div>
254
+
255
+ <div>
256
+
257
+ <p><%= link_to 'View profile', user_path(user) %></p>
258
+
259
+ </div>
260
+
261
+ </div>
262
+
263
+ </li>
264
+
265
+ <% end %>
266
+
267
+ </ul>
268
+
269
+ <%= paginate users %>
270
+
271
+ <% end %>
272
+
273
+ ```
274
+
275
+
276
+
277
+ ```
278
+
279
+ show.html.erb
280
+
281
+
282
+
283
+ <div class="row">
284
+
285
+ <aside class="col-sm-4">
286
+
287
+ <div class="card">
288
+
289
+ <div class="card-header">
290
+
291
+ <h3 class="card-title"><%= @user.name %></h3>
292
+
293
+ </div>
294
+
295
+ <div class="card-body">
296
+
297
+ <img class="rounded img-fluid" src="<%= gravatar_url(@user, { size: 500 }) %>" alt="">
298
+
299
+ </div>
300
+
301
+ </div>
302
+
303
+ <%= render 'relationships/follow_button', user: @user %>
304
+
305
+ </aside>
306
+
307
+ <div class="col-sm-8">
308
+
309
+ <ul class="nav nav-tabs nav-justified mb-3">
310
+
311
+ <li class="nav-item"><a href="<%= likes_user_path(@user) %>" class="nav-link <%= 'active' if current_page?(likes_user_path(@user)) %>">Favorites <span class="badge badge-secondary"><%= @count_favorites %></span></a></li>
312
+
313
+ <li class="nav-item"><a href="<%= user_path(@user) %>" class="nav-link <%= 'active' if current_page?(user_path(@user)) %>">Microposts <span class="badge badge-secondary"><%= @count_microposts %></span></a></li>
314
+
315
+ <li class="nav-item"><a href="<%= followings_user_path(@user) %>" class="nav-link <%= 'active' if current_page?(followings_user_path(@user)) %>">Followings <span class="badge badge-secondary"><%= @count_followings %></span></a></li>
316
+
317
+ <li class="nav-item"><a href="<%= followers_user_path(@user) %>" class="nav-link <%= 'active' if current_page?(followers_user_path(@user)) %>">Followers <span class="badge badge-secondary"><%= @count_followers %></span></a></li>
318
+
319
+ </ul>
320
+
321
+ <%= render 'microposts/microposts', microposts: @microposts %>
322
+
323
+ </div>
324
+
325
+ </div>
326
+
327
+ ```
328
+
145
329
  ### 試したこと
146
330
 
147
331
  最初はパラメータが間違っているかと思い、「favorites_controller.rb」の(params[:micropost_id])を「:favorite id」等に修正を試みましたが、直りませんでした。