开发者

custom error message for inclusion validation

开发者 https://www.devze.com 2023-03-24 00:07 出处:网络
I am using inclusion validation as validates :field_type, :inclusion => %w(SA LA RB CB SB Date) now when the validation is fired, I am getting \"Field type is not included in the list\". It is

I am using inclusion validation as

validates :field_type, :inclusion => %w(SA LA RB CB SB Date)

now when the validation is fired, I am getting "Field type is not included in the list". It is not making any sense to me. So, I want to have my own custom message saying "This value is n开发者_开发问答ot included in Field Type." Can anyone guide me here?


I think you want:

validates :field_type, :inclusion => { :in => %w(SA LA RB CB SB Date),
                                       :message => "The value: %{value} is not included in Field Type." }

See this post.


Try the message option

validates :field_type, :inclusion => %w(SA LA RB CB SB Date), :message => "...."

http://guides.rubyonrails.org/v3.2.13/active_record_validations_callbacks.html#message

0

精彩评论

暂无评论...
验证码 换一张
取 消