Mercurial > zeropaste
comparison app/controllers/pastes_controller.rb @ 321:fec39456dcbe
Better request format checker.
Didn't quite work when using curl.
author | edogawaconan <me@myconan.net> |
---|---|
date | Sun, 06 Apr 2014 03:20:10 +0900 |
parents | 612bc7c32324 |
children | 430dadffd91e |
comparison
equal
deleted
inserted
replaced
320:612bc7c32324 | 321:fec39456dcbe |
---|---|
70 correct_path = request.fullpath.downcase | 70 correct_path = request.fullpath.downcase |
71 redirect_to correct_path, :status => :moved_permanently unless | 71 redirect_to correct_path, :status => :moved_permanently unless |
72 correct_path == request.fullpath | 72 correct_path == request.fullpath |
73 end | 73 end |
74 | 74 |
75 def cache_key(format = request.format) | 75 def cache_key(format = request.format.symbol) |
76 ext = case format | 76 ext = case format |
77 when Mime::TXT | 77 when :txt |
78 ".txt" | 78 ".txt" |
79 when Mime::HTML | 79 when :html, nil |
80 "" | 80 "" |
81 else | 81 else |
82 ".unknown" | 82 ".unknown" |
83 end | 83 end |
84 "pastes:#{@paste.to_param}#{ext}" | 84 "pastes:#{@paste.to_param}#{ext}" |
89 render_to_string :show | 89 render_to_string :show |
90 end | 90 end |
91 end | 91 end |
92 | 92 |
93 def uncache | 93 def uncache |
94 [Mime::TXT, Mime::HTML, "others"].each do |format| | 94 [:txt, :html, :unknown].each do |format| |
95 Rails.cache.delete cache_key(format) | 95 Rails.cache.delete cache_key(format) |
96 end | 96 end |
97 end | 97 end |
98 | 98 |
99 def paste_params | 99 def paste_params |