From 18e027feb9582ec61c3f6a8c542d91cf1aacc28f Mon Sep 17 00:00:00 2001 From: joshua stein Date: Wed, 1 Apr 2015 01:02:22 -0500 Subject: [PATCH] add a short id redirector for comments --- app/controllers/comments_controller.rb | 8 ++++++++ config/routes.rb | 2 ++ 2 files changed, 10 insertions(+) diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index f880213..0ef4394 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 7023169..3f2a368 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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"