有没有办法在开发模式下禁用友好 ID?
谢谢!
您可以在模型中检查 rails 环境。
class User < ActiveRecord::Base
unless Rails.env.development?
extend FriendlyId
friendly_id :name, use: :slugged
end
end
跳过在开发中生成新的 slug
class User < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged
def should_generate_new_friendly_id?
false if Rails.env.development?
end
end
尝试从您的 Gemfile 中删除它:
gem 'friendly_id'
并将其添加到您的 Gemfile 中:
group :production, :test do
gem 'friendly_id'
end