问题描述
假设我们不想允许用户名是banned = ['badWordOne','otherbadword','notthiseither']
我们该怎么做?
我尝试使用acceptance
,并直观地将accept
更改为reject
,但这是行不通的:
banned_names = ['badWordOne','notthiseither']
validates :username,acceptance: { reject: banned_names },if: :username
解决方法
我想我在exclusion
banned_names = ['badWordOne','otherbadword','notthiseither']
validates :username,exclusion: { in: banned_names },if: :username