railsとredisでランキング機能を作っていて、投稿詳細ページにランキングを表示させたいのですが、例えば、posts/1を削除した場合、他の投稿の詳細ページに行くと、ランキングの中にposts/1がないため、以下のような画面が表示されてしまします。
posts/1が削除された場合、ランキングからもposts/1を削除したいのですが、どのようにしたらいいのかわかるかたが入れば知恵をお貸しください。
posts/controller
1def show 2 @post = Post.find(params[:id]) 3 4 @pv = REDIS.incr "posts/#{@post.id}" 5 @pv_num = REDIS.zincrby "posts/", 1, "#{@post.id}" 6 @ids = REDIS.zrevrange "posts/", 0, 2 7 @ranking_articles = @ids.map{ |id| Post.find(id) } 8 9 end
show.html.erb
1<ul> 2 <% @ranking_articles.each do |ranking_article| %> 3 <li><%= ranking_article.title %>(<%= REDIS.get "posts/#{ranking_article.id}" %>PV)</li> 4 <% end %> 5</ul> 6
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/03/03 03:34
2018/03/03 03:35