开发者

Rails 3 - Validates :handle does not equal one of these words

开发者 https://www.devze.com 2023-02-14 11:19 出处:网络
in my app, I allow users to create a handle. user.rb (:handle) What I would like to do is have a blacklist of words that can not be used, like \"support\", \"staff\", bad words etc...

in my app, I allow users to create a handle.

user.rb (:handle)

What I would like to do is have a blacklist of words that can not be used, like "support", "staff", bad words etc...

Is that possible using a validates method in the rails model?

Th开发者_如何学Goanks


Yes, there is validates_exclusion_of

http://ar.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000089

Disadvantage: it is sensitive to case, so "bad" and "Bad" are different words.

0

精彩评论

暂无评论...
验证码 换一张
取 消