Show the length of videos and animated posts in the thumbnail. The length is shown the top left corner in MM:SS format. This replaces the play button icon. Show a speaker icon instead of a music note icon for posts with sound. Doing this requires doing `.includes(:media_asset)` in a bunch of places to avoid N+1 queries when we access the post's duration.
32 lines
965 B
Ruby
32 lines
965 B
Ruby
class PostVotesController < ApplicationController
|
|
respond_to :js, :json, :xml, :html
|
|
|
|
def index
|
|
@post_votes = authorize PostVote.visible(CurrentUser.user).paginated_search(params, count_pages: true)
|
|
@post_votes = @post_votes.includes(:user, post: [:uploader, :media_asset]) if request.format.html?
|
|
|
|
respond_with(@post_votes)
|
|
end
|
|
|
|
def create
|
|
@post = Post.find(params[:post_id])
|
|
|
|
@post.with_lock do
|
|
@post_vote = authorize PostVote.new(post: @post, score: params[:score], user: CurrentUser.user)
|
|
PostVote.where(post: @post, user: CurrentUser.user).destroy_all
|
|
@post_vote.save
|
|
end
|
|
|
|
flash.now[:notice] = @post_vote.errors.full_messages.join("; ") if @post_vote.errors.present?
|
|
respond_with(@post_vote)
|
|
end
|
|
|
|
def destroy
|
|
@post = Post.find(params[:post_id])
|
|
@post_vote = @post.votes.find_by(user: CurrentUser.user)
|
|
|
|
authorize(@post_vote).destroy if @post_vote
|
|
respond_with(@post_vote)
|
|
end
|
|
end
|