Mercurial > zeropaste
comparison 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 | d2ef59c9a4b4 |
comparison
equal
deleted
inserted
replaced
463:4608d12ebe03 | 464:f11862e58af4 |
---|---|
1 class PastesController < ApplicationController | 1 class PastesController < ApplicationController |
2 before_action :lowercase_path, :only => :show | |
3 | |
4 # GET /1 | 2 # GET /1 |
5 # GET /1.txt | 3 # GET /1.txt |
6 def show | 4 def show |
7 @paste = Paste.safe_find(params[:id]) | 5 @paste = Paste.safe_find(params[:id]) |
8 return head :not_found unless @paste | 6 return head :not_found unless @paste |
7 | |
8 if params[:id] != @paste.to_param | |
9 redirect_to :action => :show, | |
10 :id => @paste.to_param, | |
11 :format => params[:format] | |
12 return | |
13 end | |
9 | 14 |
10 respond_to do |format| | 15 respond_to do |format| |
11 format.html | 16 format.html |
12 format.txt | 17 format.txt |
13 end | 18 end |
58 end | 63 end |
59 end | 64 end |
60 | 65 |
61 private | 66 private |
62 | 67 |
63 def lowercase_path | |
64 correct_path = request.fullpath.downcase | |
65 return if correct_path == request.fullpath | |
66 | |
67 redirect_to correct_path, :status => :moved_permanently | |
68 end | |
69 | |
70 def paste_params | 68 def paste_params |
71 params.require(:paste).permit(:paste, :paste_gzip, :paste_gzip_base64, :is_private, :key, :language) | 69 params.require(:paste).permit(:paste, :paste_gzip, :paste_gzip_base64, :is_private, :key, :language) |
72 end | 70 end |
73 end | 71 end |