我如何用友好的ID将用户slu black黑名单? [英] how do I blacklist users slugs with friendly id?
本文介绍了我如何用友好的ID将用户slu black黑名单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用友好的ID,以便用户可以有一个很好的网址。但是,我想黑名单,如api或管理员或骂人的话。我在哪里加载yaml文件来做到这一点?在模型中?
I want to use friendly id so that users can have a nice url. However I want to blacklist certain names such as api or admin or curse words. Where do I load the yaml file to do that? in the model?
推荐答案
给下面的代码尝试 -
Give the following code a try-
class MyModel < ActiveRecord::Base
extend FriendlyId
excluded_words = ["admin", "api"]
friendly_id_config.reserved_words.concat(excluded_words)
friendly_id :name, use: [:slugged, :finders]
end
这篇关于我如何用友好的ID将用户slu black黑名单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文