質問編集履歴

4

追記

2019/06/16 12:33

投稿

tomtom1
tomtom1

スコア168

test CHANGED
File without changes
test CHANGED
@@ -231,3 +231,39 @@
231
231
  //= require_tree .
232
232
 
233
233
  ```
234
+
235
+ ```Controller
236
+
237
+ class LikesController < ApplicationController
238
+
239
+ before_action :authenticate_user
240
+
241
+
242
+
243
+ def create
244
+
245
+ @posts = Post.all.order(created_at: :desc)
246
+
247
+ @post = Post.find_by(id: params[:id])
248
+
249
+ @like = Like.new(user_id: @current_user.id, post_id: params[:post_id])
250
+
251
+ @like.save
252
+
253
+ end
254
+
255
+ def destroy
256
+
257
+ @posts = Post.all.order(created_at: :desc)
258
+
259
+ @post = Post.find_by(id: params[:id])
260
+
261
+ @like = Like.find_by(user_id: @current_user.id, post_id: params[:post_id])
262
+
263
+ @like.destroy
264
+
265
+ end
266
+
267
+ end
268
+
269
+ ```

3

追記

2019/06/16 12:33

投稿

tomtom1
tomtom1

スコア168

test CHANGED
File without changes
test CHANGED
@@ -213,3 +213,21 @@
213
213
  $('#likes_buttons_<%= @post.id %>').html("<%= j(render partial: 'likes/like', locals: {post: @post}) %>");
214
214
 
215
215
  ```
216
+
217
+ ```js
218
+
219
+ *application.js
220
+
221
+ //= require rails-ujs
222
+
223
+ //= require jquery
224
+
225
+ //= require jquery_ujs
226
+
227
+ //= require activestorage
228
+
229
+ //= require turbolinks
230
+
231
+ //= require_tree .
232
+
233
+ ```

2

追記

2019/06/14 06:15

投稿

tomtom1
tomtom1

スコア168

test CHANGED
File without changes
test CHANGED
@@ -160,12 +160,16 @@
160
160
 
161
161
  ```index
162
162
 
163
+ <% @posts.each do |post| %>
164
+
163
165
  <div id='likes_buttons_<%= post.id %>'>
164
166
 
165
167
  <%= render partial: 'likes/like', locals: { post: post} %>
166
168
 
167
169
  </div>
168
170
 
171
+ <% end %>
172
+
169
173
  ```
170
174
 
171
175
  ```

1

誤字

2019/06/14 06:13

投稿

tomtom1
tomtom1

スコア168

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  現在、Ajax無しではredirect_toで処理でいいね!処理をしている状態です。そこでAjaxと取り入れ、ページの更新無しに部分更新をしたく存じます。
6
6
 
7
- https://qiita.com/YuitoSato/items/94913d6a349a530b2ea2を参考に作っています。
7
+ https://qiita.com/naberina/items/c6b5c8d7756cb882fb20を参考に作っています。
8
8
 
9
9
 
10
10