質問編集履歴

4

情報追加

2016/10/21 12:09

投稿

s.k
s.k

スコア423

test CHANGED
File without changes
test CHANGED
@@ -52,8 +52,6 @@
52
52
 
53
53
  @good.save
54
54
 
55
- redirect_to Shop.find(params[:id])
56
-
57
55
  end
58
56
 
59
57
 
@@ -66,8 +64,6 @@
66
64
 
67
65
  @good.destroy
68
66
 
69
- redirect_to Shop.find(params[:id])
70
-
71
67
  end
72
68
 
73
69
  end
@@ -142,6 +138,234 @@
142
138
 
143
139
 
144
140
 
141
+ 【micropost/_micropost.html.erb】
142
+
143
+
144
+
145
+ ```
146
+
147
+ <li id="micropost-<%= micropost.id %>">
148
+
149
+ <!-- User ver-->
150
+
151
+ <% if @page == 2 || @account == 3 %>
152
+
153
+ <!-- ユーザーアイコン -->
154
+
155
+ <%= link_to gravatar_for(micropost.user, size: 50), micropost.user %>
156
+
157
+ <!-- ユーザー名 -->
158
+
159
+ <span class="user"><%= link_to micropost.user.username, micropost.user %></span>
160
+
161
+ <span class="content">
162
+
163
+ <!-- 投稿文 -->
164
+
165
+ <%= micropost.content %>
166
+
167
+ <!-- 投稿写真 -->
168
+
169
+ <%= image_tag micropost.picture.url if micropost.picture? %>
170
+
171
+ </span>
172
+
173
+ <!-- 投稿時間 -->
174
+
175
+ <span class="timestamp">
176
+
177
+ Posted <%= time_ago_in_words(micropost.created_at) %> ago.
178
+
179
+ </span>
180
+
181
+
182
+
183
+ <!-- 削除リンク -->
184
+
185
+ <% if current_user?(micropost.user) %>
186
+
187
+ <%= link_to "delete", micropost, method: :delete, data: { confirm: "You sure?" } %>
188
+
189
+ <% end %>
190
+
191
+
192
+
193
+ <!-- お気に入り登録リンク user-to-user-->
194
+
195
+ <% if user_signed_in? %>
196
+
197
+ <% if !current_user?(micropost.user) %>
198
+
199
+ <div id="follow_form">
200
+
201
+ <%= render 'favorites/favorite_links', micropost: micropost %>
202
+
203
+ </div>
204
+
205
+ <% end %>
206
+
207
+ <% end %>
208
+
209
+ <!-- Shop ver-->
210
+
211
+ <% elsif @page == 1 || @account == 4 %>
212
+
213
+ <!-- ショップアイコン -->
214
+
215
+ <%= link_to gravatar_to(micropost.shop, size: 50), micropost.shop %>
216
+
217
+ <!-- ショップ名 -->
218
+
219
+ <span class="shop"><%= link_to micropost.shop.shopname, micropost.shop %></span>
220
+
221
+ <span class="content">
222
+
223
+ <!-- 投稿文 -->
224
+
225
+ <%= micropost.content %>
226
+
227
+ <!-- 投稿写真 -->
228
+
229
+ <%= image_tag micropost.picture.url if micropost.picture? %>
230
+
231
+ </span>
232
+
233
+ <!-- 投稿時間 -->
234
+
235
+ <span class="timestamp">
236
+
237
+ Posted <%= time_ago_in_words(micropost.created_at) %> ago.
238
+
239
+ </span>
240
+
241
+
242
+
243
+ <!-- 削除リンク -->
244
+
245
+ <% if current_shop?(micropost.shop) %>
246
+
247
+ <%= link_to "delete", micropost, method: :delete, data: { confirm: "You sure?" } %>
248
+
249
+ <% end %>
250
+
251
+
252
+
253
+ <!-- いいね!リンク shop-to-shop -->
254
+
255
+ <% if shop_signed_in? %>
256
+
257
+ <% if !current_shop?(micropost.shop) %>
258
+
259
+ <div id="follow_form">
260
+
261
+ <%= render 'likes/like_links', micropost: micropost %>
262
+
263
+ </div>
264
+
265
+ <% end %>
266
+
267
+ <% end %>
268
+
269
+
270
+
271
+ <!-- お気に入り登録リンク user-to-shop -->←ここから本件該当部分です!
272
+
273
+ <% if user_signed_in? %>
274
+
275
+ <% if !current_user?(micropost.user) %>
276
+
277
+ <div id="follow_form">
278
+
279
+ <%= render 'goods/good_links', micropost: micropost %>
280
+
281
+ </div>
282
+
283
+ <% end %>
284
+
285
+ <% end %>←ここまで本件該当部分です!
286
+
287
+
288
+
289
+ <% end %>
290
+
291
+ </li>
292
+
293
+ ```
294
+
295
+
296
+
297
+
298
+
299
+ 一応、パーシャルも追記します!
300
+
301
+
302
+
303
+ 【goods/_good_links.html.erb】
304
+
305
+
306
+
307
+ ```
308
+
309
+ <% if micropost.gooded_by? current_user %>
310
+
311
+ <%= link_to "お気に入りの解除", micropost_goods_path(micropost.id), method: :delete, remote: true %>
312
+
313
+ <% else %>
314
+
315
+ <%= link_to "お気に入り登録", micropost_goods_path(micropost.id), method: :post, remote: true %>
316
+
317
+ <% end %>
318
+
319
+ ```
320
+
321
+
322
+
323
+ pathの定義も書いておきます!
324
+
325
+
326
+
327
+ 【routes.rb】
328
+
329
+
330
+
331
+ ```
332
+
333
+ 省略
334
+
335
+ resources :microposts, only:[:create, :destroy] do
336
+
337
+ resource :favorites, only: [:create, :destroy]
338
+
339
+ resource :likes, only: [:create, :destroy]
340
+
341
+ resource :goods, only: [:create, :destroy]
342
+
343
+ end
344
+
345
+ 省略
346
+
347
+ ```
348
+
349
+
350
+
351
+ 【micropost.rb】
352
+
353
+
354
+
355
+ ```
356
+
357
+ 省略
358
+
359
+ def gooded_by? user
360
+
361
+ goods.where(user_id: user.id).exists?
362
+
363
+ end
364
+
365
+ 省略
366
+
367
+ ```
368
+
145
369
 
146
370
 
147
371
  何個か違う引数を試したのですがだめでした。。。

3

情報追加

2016/10/21 12:09

投稿

s.k
s.k

スコア423

test CHANGED
File without changes
test CHANGED
@@ -27,6 +27,8 @@
27
27
  いいね!機能のコントローラーである、goods_controller.rb中のcreateメソッド・destroyメソッドのredirect_to Shop.find(params[:id])が作動しません。
28
28
 
29
29
 
30
+
31
+ →いいね!リンクを押しても更新ボタンを押さない限り表示がいいね!を取り消すに切り替わりません。
30
32
 
31
33
 
32
34
 

2

情報追加

2016/10/21 07:38

投稿

s.k
s.k

スコア423

test CHANGED
File without changes
test CHANGED
@@ -116,6 +116,30 @@
116
116
 
117
117
 
118
118
 
119
+ 【create.js.erb】
120
+
121
+ ```
122
+
123
+ $('#follow_form').html('<%= escape_javascript(render("goods/good_links")) %>');
124
+
125
+
126
+
127
+ ```
128
+
129
+
130
+
131
+ 【destroy.js.erb】
132
+
133
+
134
+
135
+ ```
136
+
137
+ $('#follow_form').html('<%= escape_javascript(render("microposts/micropost")) %>');
138
+
139
+ ```
140
+
141
+
142
+
119
143
 
120
144
 
121
145
  何個か違う引数を試したのですがだめでした。。。

1

情報追加

2016/10/21 07:35

投稿

s.k
s.k

スコア423

test CHANGED
File without changes
test CHANGED
@@ -50,7 +50,7 @@
50
50
 
51
51
  @good.save
52
52
 
53
- redirect_to @shop
53
+ redirect_to Shop.find(params[:id])
54
54
 
55
55
  end
56
56
 
@@ -119,3 +119,5 @@
119
119
 
120
120
 
121
121
  何個か違う引数を試したのですがだめでした。。。
122
+
123
+ ヘルプミーです。。。