文字列であるscreen_nameという行を持つusersテーブルがあります。
他の制約の中でも、画面名に。のような文字を含めることはできません。、&%@など。この目的のために、次のバリデーターを作成しました。
validates :screen_name, presence: true,
length: { maximum: 15 },
uniqueness: { case_sensitive: false },
format: { with: /\w+/ }
次にfoo.barのようなスクリーン名を入力すると、それは喜んで受け入れられ、データベースに保存されました。
私は何が間違っているのですか?
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# name :string(255)
# email :string(255)
# created_at :datetime not null
# updated_at :datetime not null
# password_digest :string(255)
# remember_token :string(255)
# admin :boolean default(FALSE)
# screen_name :string(255)
#