mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
Handle /t/only-the-slug urls by trying to find the topic by slug (second try)
This commit is contained in:
@ -21,19 +21,18 @@ class TopicsController < ApplicationController
|
||||
|
||||
before_filter :consider_user_for_promotion, only: :show
|
||||
|
||||
skip_before_filter :check_xhr, only: [:avatar, :show, :feed, :redirect_to_show]
|
||||
skip_before_filter :check_xhr, only: [:avatar, :show, :feed]
|
||||
caches_action :avatar, cache_path: Proc.new {|c| "#{c.params[:post_number]}-#{c.params[:topic_id]}" }
|
||||
|
||||
def redirect_to_show
|
||||
topic_query = ((num = params[:id].to_i) > 0 and num.to_s == params[:id].to_s) ? Topic.where(id: num) : Topic.where(slug: params[:id])
|
||||
topic = topic_query.includes(:category).first
|
||||
raise Discourse::NotFound unless topic
|
||||
redirect_to topic.relative_url
|
||||
end
|
||||
|
||||
def show
|
||||
opts = params.slice(:username_filters, :best_of, :page, :post_number, :posts_before, :posts_after, :best)
|
||||
@topic_view = TopicView.new(params[:id] || params[:topic_id], current_user, opts)
|
||||
begin
|
||||
@topic_view = TopicView.new(params[:id] || params[:topic_id], current_user, opts)
|
||||
rescue Discourse::NotFound
|
||||
topic = Topic.where(slug: params[:id]).first
|
||||
raise Discourse::NotFound unless topic
|
||||
return redirect_to(topic.relative_url)
|
||||
end
|
||||
|
||||
raise Discourse::NotFound if @topic_view.posts.blank? && !(opts[:best].to_i > 0)
|
||||
|
||||
|
Reference in New Issue
Block a user