我想使用友好ID,以便用户可以拥有一个不错的网址。但是我想将某些名称列入黑名单,例如api或admin或诅咒词。我在哪里加载yaml文件来做到这一点?在模型中?
答案 0 :(得分:1)
尝试使用以下代码 -
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
答案 1 :(得分:0)
def check_slug_blacklist
blacklist = YAML.load_file(Rails.root.join('config/blacklist.yml'))
if blacklist.include?(self.slug)
self.errors.add :slug, "Please choose to a different slug" # TO DO USE I18n
end
end