fixes #2415: "Random post" causes RecordNotFound exceptions

This commit is contained in:
r888888888
2017-01-18 14:12:12 -08:00
parent a919da4dd6
commit bfa56a860c
4 changed files with 27 additions and 24 deletions

View File

@@ -93,7 +93,7 @@ class PostsController < ApplicationController
def random
count = Post.fast_count(params[:tags], :statement_timeout => CurrentUser.user.statement_timeout)
@post = Post.tag_match(params[:tags]).reorder("").offset(rand(count)).first
@post = Post.tag_match(params[:tags]).random
raise ActiveRecord::RecordNotFound if @post.nil?
respond_with(@post) do |format|
format.html { redirect_to post_path(@post, :tags => params[:tags]) }