friendly_id 的未定义方法 `slug_limit='

undefined method `slug_limit=' for friendly_id

当我根据初始化程序中的文档在 friendly_id 上设置 slug_limit 时,我看到以下错误:

Failure/Error: extend FriendlyId

NoMethodError:
  undefined method `slug_limit=' for #<#<Class:0x00007ffe66dd01a0>:0x00007ffe66dd0150>
# ./config/initializers/friendly_id.rb:68:in `block in <top (required)>'

我的模型实现 friendly_id 是这样的:

extend FriendlyId
friendly_id :title, use: [:slugged, :finders]

如何设置 slug 限制?

您可以尝试从 test example:

中像这样设置 slug_limit
extend FriendlyId
friendly_id :title, use: :slugged, slug_limit: 40