Files
danbooru/app/controllers/post_replacements_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

45 lines
1.2 KiB
Ruby

class PostReplacementsController < ApplicationController
respond_to :html, :xml, :json, :js
before_action :moderator_only, except: [:index]
def new
@post_replacement = Post.find(params[:post_id]).replacements.new
respond_with(@post_replacement)
end
def create
@post = Post.find(params[:post_id])
@post_replacement = @post.replace!(create_params)
flash[:notice] = "Post replaced"
respond_with(@post_replacement, location: @post)
end
def update
@post_replacement = PostReplacement.find(params[:id])
@post_replacement.update(update_params)
respond_with(@post_replacement)
end
def index
params[:search][:post_id] = params.delete(:post_id) if params.has_key?(:post_id)
@post_replacements = PostReplacement.paginated_search(params)
respond_with(@post_replacements)
end
private
def create_params
params.require(:post_replacement).permit(:replacement_url, :replacement_file, :final_source, :tags)
end
def update_params
params.require(:post_replacement).permit(
:file_ext_was, :file_size_was, :image_width_was, :image_height_was, :md5_was,
:file_ext, :file_size, :image_width, :image_height, :md5,
:original_url, :replacement_url
)
end
end