質問編集履歴

1

タイトル 他の選択肢のお願い等

2019/02/24 06:51

投稿

szngk
szngk

スコア14

test CHANGED
@@ -1 +1 @@
1
- ジャンル別 ランキングについて
1
+ ジャンル別 ランキング (Couldn't find all Posts with 'id':) (found 2 results, but was looking for 11)
test CHANGED
@@ -1,19 +1,27 @@
1
- 投稿サイトを作成中で、ジャンル別に、いいね!の数のランキングを表示しのですが以下のエラーが出ます。 (if --- ? 等追加してみたのですがよくわかりません。) どうしたらいいでしょうか? (Windows10 Ruby 2.4.4 Rails 5.1.6)
1
+ 投稿サイトを作成中で、ジャンル別に、いいね!の数のランキングを表示しようとしています。
2
2
 
3
3
 
4
4
 
5
- ```Ruby
5
+ ① 以下のエラーが出ます。どうしたらいいでしょうか? (Windows10 Ruby 2.4.4 Rails 5.1.6)
6
+
7
+
6
8
 
7
9
  ActiveRecord::RecordNotFound in PostsController#index
8
10
 
9
- Couldn't find all Posts with 'id': (#<Like:0x000000000597d290>, #<Like:0x0000000005977cc8>, #<Like:0x00000000059747f8>, #<Like:0x000000000596acd0>, #<Like:0x0000000005956c58>, #<Like:0x000000000594dea0>, #<Like:0x0000000005931bb0>, #<Like:0x000000000591cfd0>, #<Like:0x00000000058b5c18>, #<Like:0x00000000058a7c80>, #<Like:0x000000000587a168>) (found 2 results, but was looking for 11)
10
-
11
- ```
11
+ Couldn't find all Posts with 'id': (#<Like:0x000000000d1d0440>, #<Like:0x000000000d1d02d8>, #<Like:0x000000000d1d0170>, #<Like:0x000000000d1d0030>, #<Like:0x000000000d1cbeb8>, #<Like:0x000000000d1cbd78>, #<Like:0x000000000d1cbc38>, #<Like:0x000000000d1cbaa8>, #<Like:0x000000000d1cb8c8>, #<Like:0x000000000d1cb788>, #<Like:0x000000000d1cb620>) (found 2 results, but was looking for 11)
12
12
 
13
13
 
14
14
 
15
- ```Ruby
15
+ PostsController#index エラー箇所
16
16
 
17
- @genre_like_ranking = Post.group(:genre_id).find(Like.group(:post_id).order(Arel.sql('count(*) desc')))
17
+  @posts = Post.group(:genre_id).find(Like.group(:post_id).order('count(post_id) desc')).limit(15).pluck(:post_id).page(params[:page])
18
18
 
19
+
20
+
21
+
22
+
19
- ```
23
+ ② ransackを使用して、ジャンル別ランキングを表示できますか?
24
+
25
+ (いいねの数がカラムではないため無理のようですが、ransackを使用すると表示が簡単なので、もし容易にできるようでしたら宜しくお願い致します。)
26
+
27
+ (Redis等他の方法で、初心者が使用しやすいものがあれば御提案頂ければ大変助かります。)