diff app/controllers/pastes_controller.rb @ 464:f11862e58af4

Canonicalize 0-prefixed ids as well
author nanaya <me@nanaya.pro>
date Mon, 10 Dec 2018 02:38:45 +0900
parents 080dd141898c
children
line wrap: on
line diff
--- a/app/controllers/pastes_controller.rb	Mon Dec 10 02:35:08 2018 +0900
+++ b/app/controllers/pastes_controller.rb	Mon Dec 10 02:38:45 2018 +0900
@@ -1,12 +1,17 @@
 class PastesController < ApplicationController
-  before_action :lowercase_path, :only => :show
-
   # GET /1
   # GET /1.txt
   def show
     @paste = Paste.safe_find(params[:id])
     return head :not_found unless @paste
 
+    if params[:id] != @paste.to_param
+      redirect_to :action => :show,
+        :id => @paste.to_param,
+        :format => params[:format]
+      return
+    end
+
     respond_to do |format|
       format.html
       format.txt
@@ -60,13 +65,6 @@
 
   private
 
-  def lowercase_path
-    correct_path = request.fullpath.downcase
-    return if correct_path == request.fullpath
-
-    redirect_to correct_path, :status => :moved_permanently
-  end
-
   def paste_params
     params.require(:paste).permit(:paste, :paste_gzip, :paste_gzip_base64, :is_private, :key, :language)
   end