forum post votes: add index page.

This commit is contained in:
evazion
2019-10-27 23:05:48 -05:00
parent d617b20b49
commit 0e159960a2
10 changed files with 92 additions and 19 deletions

View File

@@ -1,32 +1,27 @@
class ForumPostVotesController < ApplicationController
respond_to :js
before_action :load_forum_post
before_action :load_vote, only: [:destroy]
before_action :member_only
respond_to :html, :xml, :json, :js
before_action :member_only, only: [:create, :destroy]
def index
@forum_post_votes = ForumPostVote.includes(creator: [], forum_post: [:topic]).paginated_search(params)
respond_with(@forum_post_votes)
end
def create
@forum_post = ForumPost.find(params[:forum_post_id])
@forum_post_vote = @forum_post.votes.create(forum_post_vote_params)
respond_with(@forum_post_vote)
end
def destroy
@forum_post_vote = CurrentUser.user.forum_post_votes.find(params[:id])
@forum_post_vote.destroy
respond_with(@forum_post_vote)
end
private
def load_vote
@forum_post_vote = @forum_post.votes.where(creator_id: CurrentUser.id).first
raise ActiveRecord::RecordNotFound.new if @forum_post_vote.nil?
end
def load_forum_post
@forum_post = ForumPost.find(params[:forum_post_id])
end
def forum_post_vote_params
params.fetch(:forum_post_vote, {}).permit(:score)
end
end