title: Add random unique reference to Rails Friendly_id vanity URL
body: <p>I have a <em>Product</em> model that contains the product name and a unique reference randomly generated before the product creation. I want to use both to generate a frindly_id URL. Here is my try:</p>
  
  <pre><code># == Schema Information
  #
  # Table name: products
  #
  #  name        :string           not null
  #  slug        :string
  #  reference   :string
  #
  class Product &lt; ActiveRecord::Base
    extend FriendlyId
  
    before_create :generate_unique_reference
    friendly_id :friendly_id_syntax, use: :slugged
  
    def generate_unique_reference
      self.reference = SecureRandom.hex(3).upcase
    end
  
    def friendly_id_syntax
      [
        [:name, :reference]
      ]
    end
  end
  </code></pre>
  
  <p>This generates a vanity URL that only contains the product name (without the product reference). Seems the slug generation is done when the <em>reference</em> attribute is still <em>nil</em>. I have the same result when I put the <code>friendly_id :friendly_id_syntax, use: :slugged</code> before the <code>before_create</code>.</p>
  
  <p>Have any idea?</p>