ruby on rails - Enabling history after using friendly_id for a while -


i'm trying add history existing production site. hadn't generated friendly_id migration after adding , changing use: :sluggable use: [:sluggable, :history] model, ability model.friendly.find... gone on objects in model before made change.

what's best way address this. should loop through , .save on every record in model during migration? that's i've thought of doing far. not sure if work, there must better way.

update

what mentioned in original question how went it. seems clumsy, worked. i'd still love better answer if 1 out there.

# added friendly_id migration class createfriendlyidslugs < activerecord::migration   def     model.all.each |m|       m.save     end   end end 

this should work both mysql , postgresql (which doesn't have insert ignore)

def   execute <<-sql     insert friendly_id_slugs       (slug, sluggable_id, sluggable_type, created_at)     select m.slug, m.id, 'model', now()     models m     left outer join friendly_id_slugs f on f.sluggable_id = m.id     m.slug not null , length(m.slug) > 0 , f.id null   sql end 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -