From 3bc92f1ca75464270e45f2df3a44fb453a922265 Mon Sep 17 00:00:00 2001 From: Toks Date: Tue, 9 Jun 2015 18:15:50 -0400 Subject: [PATCH] #1938 Add order:random as alternative random trigger --- app/assets/javascripts/autocomplete.js | 3 ++- app/controllers/posts_controller.rb | 3 ++- app/views/posts/partials/index/_posts.html.erb | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/autocomplete.js b/app/assets/javascripts/autocomplete.js index 4cdf8c322..9fb1b7405 100644 --- a/app/assets/javascripts/autocomplete.js +++ b/app/assets/javascripts/autocomplete.js @@ -267,7 +267,8 @@ "mpixels", "mpixels_asc", "portrait", "landscape", "filesize", "filesize_asc", - "rank" + "rank", + "random" ], status: [ "any", "deleted", "active", "pending", "flagged", "banned" diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 0c4ecad4c..422a372b9 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -14,7 +14,8 @@ class PostsController < ApplicationController redirect_to post_path(@post) else limit = params[:limit] || (params[:tags] =~ /(?:^|\s)limit:(\d+)(?:$|\s)/ && $1) || CurrentUser.user.per_page - @post_set = PostSets::Post.new(tag_query, params[:page], limit, params[:raw], params[:random]) + @random = params[:random] || params[:tags] =~ /(?:^|\s)order:random(?:$|\s)/ + @post_set = PostSets::Post.new(tag_query, params[:page], limit, params[:raw], @random) @posts = @post_set.posts respond_with(@posts) do |format| format.atom diff --git a/app/views/posts/partials/index/_posts.html.erb b/app/views/posts/partials/index/_posts.html.erb index c33b91acd..d71e5912a 100644 --- a/app/views/posts/partials/index/_posts.html.erb +++ b/app/views/posts/partials/index/_posts.html.erb @@ -9,7 +9,7 @@ <% end %> - <% unless params[:random].present? %> + <% unless @random.present? %> <%= numbered_paginator(post_set.posts) %> <% end %>