Permalink
Browse files

Taxon permalink should not have a trailing slash.

See SeoAssist middleware to more details.
  • Loading branch information...
1 parent d27d575 commit 7f8e59e999894d9c6491a25cc9f8fcec641b2d85 @romul romul committed Feb 1, 2011
Showing with 5 additions and 11 deletions.
  1. +1 −1 core/app/controllers/taxons_controller.rb
  2. +2 −8 core/app/models/taxon.rb
  3. +2 −2 core/lib/middleware/seo_assist.rb
View
2 core/app/controllers/taxons_controller.rb
@@ -14,7 +14,7 @@ def load_data
end
def object
- @object ||= end_of_association_chain.find_by_permalink(params[:id] + "/")
+ @object ||= end_of_association_chain.find_by_permalink(params[:id])
end
def accurate_title
View
10 core/app/models/taxon.rb
@@ -4,7 +4,6 @@ class Taxon < ActiveRecord::Base
belongs_to :taxonomy
has_and_belongs_to_many :products
before_create :set_permalink
- before_save :ensure_trailing_slash
validates :name, :presence => true
has_attached_file :icon,
@@ -30,10 +29,10 @@ def applicable_filters
# Creates permalink based on .to_url method provided by stringx gem
def set_permalink
if parent_id.nil?
- self.permalink = name.to_url + "/" if self.permalink.blank?
+ self.permalink = name.to_url if self.permalink.blank?
else
parent_taxon = Taxon.find(parent_id)
- self.permalink = parent_taxon.permalink + (self.permalink.blank? ? name.to_url : self.permalink.split("/").last) + "/"
+ self.permalink = [parent_taxon.permalink, (self.permalink.blank? ? name.to_url : self.permalink.split("/").last)].join('/')
end
end
@@ -48,9 +47,4 @@ def active_products
def escape(str)
str.blank? ? "" : str.to_url
end
-
- def ensure_trailing_slash
- set_permalink if self.permalink.blank?
- self.permalink += "/" unless self.permalink[-1..-1] == "/"
- end
end
View
4 core/lib/middleware/seo_assist.rb
@@ -12,8 +12,8 @@ def call(env)
params.delete('taxon')
#ensures no trailing / for taxon urls
- #TODO ensure that permalink is never stored with a trailing slash
- permalink = taxon.permalink[0...-1]
+ permalink = taxon.permalink
+ permalink = permalink[0...-1] if permalink[-1..-1] == '/'
return build_response(params, "/t/#{permalink}" )
elsif env["PATH_INFO"] =~ /^\/(t|products)(\/\S+)?\/$/

0 comments on commit 7f8e59e

Please sign in to comment.