Rails:有没有办法在开发模式下禁用友好ID?

时间:2012-09-19 09:00:58

标签: ruby-on-rails friendly-id

有没有办法在开发模式下禁用友好ID?

感谢的!

2 个答案:

答案 0 :(得分:2)

您可以在模型中查看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

答案 1 :(得分:0)

尝试从Gemfile中删除它:

gem 'friendly_id'

并在你的Gemfile上添加:

group :production, :test do
gem 'friendly_id'
end