質問編集履歴
2
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,7 +28,83 @@
|
|
28
28
|
|
29
29
|
|
30
30
|
|
31
|
-
###
|
31
|
+
### ソースコード
|
32
|
+
|
33
|
+
EnemyBadsController
|
34
|
+
|
35
|
+
class EnemyBadsController < ApplicationController
|
36
|
+
|
37
|
+
before_action :post_params
|
38
|
+
|
39
|
+
def create
|
40
|
+
|
41
|
+
EnemyBad.create(user_id: current_user.id, post_id: params[:id])
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
def destroy
|
48
|
+
|
49
|
+
EnemyBad.find_by(user_id: current_user.id, post_id: params[:id]).destroy
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
def post_params
|
58
|
+
|
59
|
+
@post = Post.find(params[:id])
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
app/views/enemy_bads/create.js.erb
|
68
|
+
|
69
|
+
document.getElementById(post_<%= @post.id %>).innerHTML = '<%= j(render @post) %>'
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
app/views/enemy_bads/destroy.js.erb
|
74
|
+
|
75
|
+
document.getElementById('post_<%= @post.id %>').innerHTML = '<%= j(render @post) %>'
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
app/views/posts/_post.html.erb
|
80
|
+
|
81
|
+
<td><%= link_to 'いいねを外す', destroy_enemy_bad_path(post), method: :DELETE, remote: true %><%= post.enemy_bad.count %></td>
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
app/views/posts/index.html.erb
|
86
|
+
|
87
|
+
<%= form_with(url: search_posts_path, local: true, method: :get, class: "search-form") do |form| %>
|
88
|
+
|
89
|
+
<%= form.text_field :keyword, placeholder: "投稿を検索する", class: "search-input" %>
|
90
|
+
|
91
|
+
<%= form.submit "検索", class: "search-btn" %>
|
92
|
+
|
93
|
+
<% end %>
|
94
|
+
|
95
|
+
<div class="contents row">
|
96
|
+
|
97
|
+
<% @posts.each do |post| %>
|
98
|
+
|
99
|
+
<tr id="post_<%= post.id %>">
|
100
|
+
|
101
|
+
<%= render partial: "post", locals: { post: post } %>
|
102
|
+
|
103
|
+
</tr>
|
104
|
+
|
105
|
+
<% end %>
|
106
|
+
|
107
|
+
</div>
|
32
108
|
|
33
109
|
|
34
110
|
|
1
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,91 +30,7 @@
|
|
30
30
|
|
31
31
|
### 該当のソースコード
|
32
32
|
|
33
|
-
EnemyBadsController
|
34
33
|
|
35
|
-
class EnemyBadsController < ApplicationController
|
36
|
-
|
37
|
-
before_action :post_params
|
38
|
-
|
39
|
-
def create
|
40
|
-
|
41
|
-
EnemyBad.create(user_id: current_user.id, post_id: params[:id])
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
def destroy
|
48
|
-
|
49
|
-
EnemyBad.find_by(user_id: current_user.id, post_id: params[:id]).destroy
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
def post_params
|
58
|
-
|
59
|
-
@post = Post.find(params[:id])
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
app/views/enemy_bads/create.js.erb
|
68
|
-
|
69
|
-
document.getElementById(post_<%= @post.id %>).innerHTML = '<%= j(render @post) %>'
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
app/views/enemy_bads/destroy.js.erb
|
74
|
-
|
75
|
-
document.getElementById('post_<%= @post.id %>').innerHTML = '<%= j(render @post) %>'
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
app/views/posts/_post.html.erb
|
80
|
-
|
81
|
-
<td><%= link_to 'いいねを外す', destroy_enemy_bad_path(post), method: :DELETE, remote: true %><%= post.enemy_bad.count %></td>
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
app/views/posts/index.html.erb
|
86
|
-
|
87
|
-
<%= form_with(url: search_posts_path, local: true, method: :get, class: "search-form") do |form| %>
|
88
|
-
|
89
|
-
<%= form.text_field :keyword, placeholder: "投稿を検索する", class: "search-input" %>
|
90
|
-
|
91
|
-
<%= form.submit "検索", class: "search-btn" %>
|
92
|
-
|
93
|
-
<% end %>
|
94
|
-
|
95
|
-
<div class="contents row">
|
96
|
-
|
97
|
-
<% @posts.each do |post| %>
|
98
|
-
|
99
|
-
<tr id="post_<%= post.id %>">
|
100
|
-
|
101
|
-
<%= render partial: "post", locals: { post: post } %>
|
102
|
-
|
103
|
-
</tr>
|
104
|
-
|
105
|
-
<% end %>
|
106
|
-
|
107
|
-
</div>
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
```ここに言語名を入力
|
112
|
-
|
113
|
-
javasqript,ruby on rails
|
114
|
-
|
115
|
-
ソースコード
|
116
|
-
|
117
|
-
```
|
118
34
|
|
119
35
|
|
120
36
|
|