Search code examples
ruby-on-railsurlfriendly-id

How to replace the UUID with random numbers using Friendly_id gem in rails?


Using Rails 4 and FriendlyId Gem version 5.Im new to Friendly id gem. Here I wanna replace my Url like profile-name-{4 (or) 5 length random numbers} instead of profile-name-Long-UUID . Thanks


Solution

  • Class Profile < ActiveRecord::Base
       extend FriendlyId
       friendly_id :slug_candidates, use: :slugged
       def slug_candidates
          [self.name, "%s %s" % [self.name, SecureRandom.hex(3)]]
       end
    end
    

    Please click here for more reference