Rails: Is there a way to disable friendly ID in development mode?
-
02-07-2021 - |
Question
Is there a way to disable friendly ID in development mode?
Thank's!
Solution
You can check rails environment in model.
class User < ActiveRecord::Base
unless Rails.env.development?
extend FriendlyId
friendly_id :name, use: :slugged
end
end
to skip generating new slug in development
class User < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged
def should_generate_new_friendly_id?
false if Rails.env.development?
end
end
OTHER TIPS
Try to remove this from your Gemfile:
gem 'friendly_id'
and add this on your Gemfile:
group :production, :test do
gem 'friendly_id'
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow