質問編集履歴

1

書式の改善

2020/09/29 08:23

投稿

kei__3
kei__3

スコア7

test CHANGED
@@ -1 +1 @@
1
- rails ページネーションとソート機能実装
1
+ NoMethodError undefined method `paginate'改善
test CHANGED
@@ -12,23 +12,11 @@
12
12
 
13
13
  ```
14
14
 
15
- ActionView::Template::Error (undefined method `total_pages' for #<Array:0x00007fffca5aa718>):
15
+ NoMethodError (undefined method `paginate' for #<Array:0x00007fffde2f4b90>):
16
-
17
- 7: <a class="btn btn-lg btn-primary" href="/posts/ranking" role="button">人気順</a>
16
+
18
-
19
- 8: </div>
17
+
20
-
21
- 9: <%= render @posts %>
18
+
22
-
23
- 10: <%= will_paginate %>
24
-
25
- 11: </div>
26
-
27
- 12: </div>
28
-
29
-
30
-
31
- app/views/posts/ranking.html.erb:10
19
+ app/controllers/posts_controller.rb:52:in `ranking'
32
20
 
33
21
  ```
34
22
 
@@ -140,11 +128,17 @@
140
128
 
141
129
  def ranking
142
130
 
143
- post= Post.paginate(page: params[:page])
131
+ @posts = Post.sort_like.paginate(page: params[:page],per_page: 15)
144
-
145
- @posts = post.sort{|a,b| b.liked_users.count <=> a.liked_users.count}
132
+
146
-
147
- end
133
+ end
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
148
142
 
149
143
 
150
144
 
@@ -168,6 +162,10 @@
168
162
 
169
163
  end
170
164
 
165
+
166
+
167
+
168
+
171
169
 
172
170
 
173
171
  end
@@ -204,15 +202,31 @@
204
202
 
205
203
  </div>
206
204
 
205
+
206
+
207
207
  <%= render @posts %>
208
208
 
209
- <%= will_paginate %>
209
+ <%= will_paginate @posts%>
210
210
 
211
211
  </div>
212
212
 
213
213
  </div>
214
214
 
215
-
215
+ ```
216
+
217
+
218
+
219
+ ###post.rb一部
220
+
221
+
222
+
223
+ ```
224
+
225
+ def self.sort_like
226
+
227
+ Post.all.sort{|a,b| b.liked_users.count <=> a.liked_users.count}
228
+
229
+ end
216
230
 
217
231
  ```
218
232