Search code examples
ruby-on-railsruby-on-rails-3friendly-id

Need to update friendly_id manually


I have a photo at the URL:

www.mysite.com/here-is-my-url

I have created a replacement for this photo but I want the old url to point to the new resource. I.e. the new resource is www.mysite.com/new-url but I want the URL to be www.mysite.com/here-is-my-url and for the old resource, I want to change it to something else altogether.

I know it's best not to manually fiddle with the friendly_id slugs, BUT this is an emergency one-off type thing and I'm trying to figure out the most painless way to do this (preferably via the console).

Any thoughts? I basically need access to the friendly_id_slugs table via the console, but I get an uninitialized constant error when I try to do FriendlyIdSlug.all .


Solution

  • def should_generate_new_friendly_id?
      slug.blank? || name_changed?
    end
    

    add that to your model. name_change? should be [whatever your column is that decides the slug]_changed?