Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

scope not updated if slug already exists #4

Open
hazah opened this issue Dec 31, 2011 · 5 comments
Open

scope not updated if slug already exists #4

hazah opened this issue Dec 31, 2011 · 5 comments

Comments

@hazah
Copy link

hazah commented Dec 31, 2011


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
@RISCfuture
Copy link
Owner

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

@hazah
Copy link
Author

hazah commented Dec 31, 2011

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
Copy link
Author

hazah commented Jan 2, 2012

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

@RISCfuture
Copy link
Owner

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

@hazah
Copy link
Author

hazah commented Jun 11, 2012

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants