slugalicious icon indicating copy to clipboard operation
slugalicious copied to clipboard

scope not updated if slug already exists

Open hazah opened this issue 13 years ago • 5 comments


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

hazah avatar Dec 31 '11 20:12 hazah

I don't understand what you're getting at. Can you describe what situation has to occur for this to fail?

RISCfuture avatar Dec 31 '11 20:12 RISCfuture

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.

hazah avatar Dec 31 '11 23:12 hazah

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

hazah avatar Jan 02 '12 16:01 hazah

I'm getting busy at work again; I'll get to this as soon as I can.

RISCfuture avatar Jan 04 '12 01:01 RISCfuture

Hey there. It's been a while. I'm wondering what your opinion is on the issue/feature?

hazah avatar Jun 11 '12 14:06 hazah