slugalicious
slugalicious copied to clipboard
scope not updated if slug already exists
Slug.transaction do
slugs.update_all(active: false)
slugs.where(slug: valid_slugs_in_use.first).update_all(active: true)
end
return
if the scope isn't already in the record, it does not seem to get saved. A new slug is not generated either. all I did to fix it is the following in your code.
Slug.transaction do
slugs.update_all(active: false)
slugs.where(slug: valid_slugs_in_use.first).update_all(
active: true,
scope: self.class._slug_scope.try(:call, self))
end
return
I don't understand what you're getting at. Can you describe what situation has to occur for this to fail?
I was setting up a slugged category model, the idea is to have it scope a particular slugged resource. Each category uses its parent's to_param + '/' as the scope of the slug for itself, unless root. i created a cat, 'parent', then 'child'. i proceeded to update child.parent = parent. the slug was updated but, the scope was not. furthermore, the cache was not flushed so i also added unmemoize_all just before the return.
Hi again. I know you're busy and this is low on the food chain. I'm only curious to know whether a) I've clarified enough or you need more information. b) I'm wondering if I'm on the right track. That is, are you aware of anything in the modification I'm showing you that could potentially cause problems? here's the full text of the code change:
Slug.transaction do
slugs.update_all(active: false)
slugs.where(slug: valid_slugs_in_use.first).update_all(
active: true,
scope: self.class._slug_scope.try(:call, self))
end
unmemoize_all
return
I'm getting busy at work again; I'll get to this as soon as I can.
Hey there. It's been a while. I'm wondering what your opinion is on the issue/feature?