#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])

View File

@ -8,5 +8,7 @@
<% if @post_set.is_tag_subscription? %>
<li><%= link_to "Edit subscriptions", tag_subscriptions_path %></li>
<% end %>
<li><%= link_to "Random post", random_posts_path(:tags => params[:tags]) %></li>
</ul>
</section>

View File

@ -3,6 +3,7 @@
<li><%= link_to "Favorite", favorites_path(:post_id => post.id), :remote => true, :method => :post, :id => "add-to-favorites", :title => "Shortcut is F" %></li>
<li><%= link_to "Unfavorite", favorite_path(post), :remote => true, :method => :delete, :id => "remove-from-favorites" %></li>
<li><%= link_to "Edit", "#", :id => "side-edit-link" %></li>
<li><%= link_to "Random post", random_posts_path(:tags => params[:tags]) %></li>
<li><%= link_to "Add to pool", "#", :id => "pool" %></li>
<% if post.is_note_locked? %>
<li><span id="note-locked-notice">Note locked</span></li>

View File

@ -156,6 +156,7 @@ Danbooru::Application.routes.draw do
resources :votes, :controller => "post_votes", :only => [:create, :destroy]
collection do
get :home
get :random
end
member do
put :revert