Files
danbooru/app/controllers/artist_commentaries_controller.rb
evazion a5ab25d0ba pagination: avoid counting pages outside searches.
Replace this common pattern in controllers:

    @tags = Tag.search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])

with this:

    @tags = Tag.paginated_search(params)

`search_count` is used to skip doing a full page count when we're not
doing a search (on the assumption that the number of results will be
high when not constrained by a search). We didn't do this consistently
though. Refactor to do this in every controller.
2019-10-07 22:02:03 -05:00

47 lines
1.4 KiB
Ruby

class ArtistCommentariesController < ApplicationController
respond_to :html, :xml, :json, :js
before_action :member_only, only: [:create_or_update, :revert]
def index
@commentaries = ArtistCommentary.paginated_search(params)
respond_with(@commentaries)
end
def search
end
def show
if params[:id]
@commentary = ArtistCommentary.find(params[:id])
else
@commentary = ArtistCommentary.find_by_post_id!(params[:post_id])
end
respond_with(@commentary) do |format|
format.html { redirect_to post_path(@commentary.post) }
end
end
def create_or_update
@artist_commentary = ArtistCommentary.find_or_initialize_by(post_id: params.dig(:artist_commentary, :post_id))
@artist_commentary.update(commentary_params)
respond_with(@artist_commentary)
end
def revert
@artist_commentary = ArtistCommentary.find_by_post_id!(params[:id])
@version = @artist_commentary.versions.find(params[:version_id])
@artist_commentary.revert_to!(@version)
end
private
def commentary_params
params.fetch(:artist_commentary, {}).except(:post_id).permit(%i[
original_description original_title translated_description translated_title
remove_commentary_tag remove_commentary_request_tag remove_commentary_check_tag remove_partial_commentary_tag
add_commentary_tag add_commentary_request_tag add_commentary_check_tag add_partial_commentary_tag
])
end
end