FIX: update category permalink if record already exists

This commit is contained in:
Arpit Jalan 2016-11-17 21:57:06 +05:30
parent 2125a630d9
commit 82bdfb9832
1 changed files with 8 additions and 2 deletions

View File

@ -467,9 +467,15 @@ SQL
def create_category_permalink
old_slug = changed_attributes["slug"]
if self.parent_category
Permalink.create(url: "c/#{self.parent_category.slug}/#{old_slug}", category_id: id)
url = "c/#{self.parent_category.slug}/#{old_slug}"
else
Permalink.create(url: "c/#{old_slug}", category_id: id)
url = "c/#{old_slug}"
end
if Permalink.where(url: url).exists?
Permalink.where(url: url).update_all(category_id: id)
else
Permalink.create(url: url, category_id: id)
end
end