我正在尝试制作一个简单的自定义验证消息。我正在使用的验证编译并运行正常,但我没有看到消息有任何变化:
validates :rating, :inclusion => { :in => 0..5 }, :presence => { :message => " must be within 0-5" }
我得到的消息仍为Rating is not included in the list
我需要验证rating
是否存在且decimal
之间是0-5
答案 0 :(得分:24)
好吧,我解决了。这是有效的验证:
validates :rating, :inclusion => { :in => 0..5, :message => " should be between 0 to 5" }
validates :rating, :presence => { :message => " cannot be blank" }
我添加了这个
validates :rating, :numericality => { :message => " should be a number" }