[英]Rails: Custom validation message
我正在嘗試制作一個簡單的自定義驗證消息。 我正在使用的驗證編譯並運行正常,但我沒有看到消息有任何變化:
validates :rating, :inclusion => { :in => 0..5 }, :presence => { :message => " must be within 0-5" }
我收到的消息仍然是Rating is not included in the list
我需要驗證rating
是否存在,並且是0-5
之間的decimal
好吧,我解決了。 這是有效的驗證:
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" }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.