add a short id redirector for comments

This commit is contained in:
joshua stein 2015-04-01 01:02:22 -05:00
parent e9f005d83b
commit 18e027feb9
2 changed files with 10 additions and 0 deletions

View file

@ -66,6 +66,14 @@ class CommentsController < ApplicationController
:content_type => "text/html", :locals => { :comment => comment }
end
def redirect_from_short_id
if comment = find_comment
return redirect_to comment.url
else
return render :text => "can't find comment", :status => 400
end
end
def edit
if !((comment = find_comment) && comment.is_editable_by_user?(@user))
return render :text => "can't find comment", :status => 400

View file

@ -84,6 +84,8 @@ Lobsters::Application.routes.draw do
get "/s/:id/:title/comments/:comment_short_id" => "stories#show"
get "/s/:id/(:title)" => "stories#show", :format => /html|json/
get "/c/:id" => "comments#redirect_from_short_id"
get "/u" => "users#tree"
get "/u/:username" => "users#show", :as => "user"