18

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 not included in Field Type." Can anyone guide me here?

2 Answers 2

26

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.

Sign up to request clarification or add additional context in comments.

2 Comments

can i add the entered value rather than this value? like if i put "none" can i display error like "none is not included in field type"
Thanks your solution worked but it was giving "Field type" in front of message, so I edited the message :message => "cannot be %{value}"
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.