friendly_id覆盖了slug urls Rails上的SecureRandom uuid /追加数字序列

sto*_*nep 2 ruby-on-rails friendly-id

我试图绕过默认的friendly_id方法,该方法验证特定slug上的uniq值.简而言之,我想绕过具有相同值的slug的friendly_id检查,并且它不会附加--1, - 2等.我需要能够使用friendly_id创建记录,这些记录都可以具有相同的段塞文本.

        class Product < ActiveRecord::Base
         extend FriendlyId
         friendly_id :title, use: :slugged # use the title column to create slug column
Run Code Online (Sandbox Code Playgroud)

Jer*_*een 5

我认为唯一的方法是使用范围允许每个副本friendly_id存在于自己的"范围空间"中.

https://github.com/norman/friendly_id/blob/master/lib/friendly_id/scoped.rb#L7

我猜是这样的(假设副本friendly_id属于不同的userss):

class Product < ActiveRecord::Base
  extend FriendlyId
  friendly_id :tite, :use => [:scoped,:slugged], :scope => :user
end
Run Code Online (Sandbox Code Playgroud)