开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜