FEATURE: add a way to map arbitrary urls to a topic, post, or category. Useful for sites that have migrated to Discourse and want to redirect from their old site to Discourse with 301 redirects.

This commit is contained in:
Neil Lalonde
2014-08-28 15:09:36 -04:00
parent 8a6c4234fc
commit 14890a6002
9 changed files with 156 additions and 0 deletions

21
app/models/permalink.rb Normal file
View File

@@ -0,0 +1,21 @@
class Permalink < ActiveRecord::Base
belongs_to :topic
belongs_to :post
belongs_to :category
before_validation :normalize_url
def normalize_url
if self.url
self.url = self.url.strip
self.url = self.url[1..-1] if url[0,1] == '/'
end
end
def target_url
return post.url if post
return topic.relative_url if topic
return category.url if category
nil
end
end