custom error message for inclusion validation
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
精彩评论