質問するログイン新規登録

質問編集履歴

1

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

2019/02/24 06:51

投稿

szngk
szngk

スコア14

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