#1938: Add random post link

This commit is contained in:
Toks
2013-09-17 15:51:41 -04:00
parent ac9a08c4ec
commit ab7d3f69a4
4 changed files with 10 additions and 0 deletions

View File

@@ -112,6 +112,12 @@ class PostsController < ApplicationController
end
end
def random
count = Post.fast_count(params[:tags])
@post = Post.tag_match(params[:tags]).offset(rand(count)).first
redirect_to post_path(@post, :tags => params[:tags])
end
private
def tag_query
params[:tags] || (params[:post] && params[:post][:tags])