Harsha M V
Harsha M V

Reputation: 54949

Friendly_id create slugs for a existing model

I have Locations models - countries/regions/cities which have in total 50k plus records. i have added the configuration to these models.

Is there a way through the command line i can create the slugs for these models at one go instead of editing and saving all the models.

Upvotes: 4

Views: 3076

Answers (2)

Eyeslandic
Eyeslandic

Reputation: 14900

friendly_id updates the slug on save-ing. I did it like this for my project, but that only included about 5k items, so this works but could take some time depending on your setup.

Model.all.map(&:save)

Upvotes: 4

Richard Peck
Richard Peck

Reputation: 76784

Save

To help you further - @iceman is right - you need to loop through your slugged models & save them again. friendly_id recommends this by doing it in the rails console:

$ rails c
$ Location.find_each(&:save)

This should help Rails load each of the items, and then save them immediately. This will trigger the slug generation functionality of friendly_id, populating the slug columns of your Location records

Upvotes: 9

Related Questions