Permalink
Browse files

Merge pull request #18 from alfajango/topic-key-trailing-slash

Make topic key trailing-slash-insensitive.
  • Loading branch information...
FooBarWidget committed Jan 30, 2013
2 parents 957e69d + e26b071 commit 7c6921d79b1dc9de11809ee03e0b529bf44959ca
Showing with 8 additions and 0 deletions.
  1. +8 −0 app/models/topic.rb
View
@@ -38,11 +38,19 @@ def self.lookup_or_create(site_key, topic_key, topic_title, topic_url)
end
end
+ def self.alt_key(topic_key)
+ topic_key.match(/\/$/) ? topic_key.chop : "#{topic_key}/"
+ end
+
private
def self.find_by_site_key_and_topic_key(site_key, topic_key)
Topic.
where('sites.key = ? AND topics.key = ?', site_key, topic_key).
joins(:site).
+ first ||
+ Topic.
+ where('sites.key = ? AND topics.key = ?', site_key, alt_key(topic_key)).
+ joins(:site).
first
end
end

0 comments on commit 7c6921d

Please sign in to comment.