设置验证规则的消息

时间:2014-01-29 17:38:05

标签: ruby-on-rails ruby validation model validates-uniqueness-of

我有这个验证规则:

  validates :email, :presence => {:message => 'Email cannot be blank.'}, :allow_blank => true, :format => {:with => /\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\z/, :message => 'Email is not valid.'}, :uniqueness => true

我想为

设置自己的留言
validates :email, :presence => {:message => 'Email cannot be blank.'}, :allow_blank => true, :format => {:with => /\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\z/, :message => 'Email is not valid.'}, :uniqueness => {message: 'This email address has already been taken.'}

但是这只会生成默认消息已经被,而不是我在消息部分中定义的消息。如何定制?

由于

0 个答案:

没有答案