Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 597
Sadiksha Gautam Avatar asked Aug 01 '11 04:08

Sadiksha Gautam


People also ask

What is custom error message?

Drivers can specify their own error types and error messages. To define a custom error message, you must first define a new IO_ERR_XXX value to specify as the ErrorCode member of the error log entry. The Event Viewer uses the IO_ERR_XXX value to look up the driver's error message.

What are validations in Rails?

Rails validation defines valid states for each of your Active Record model classes. They are used to ensure that only valid details are entered into your database. Rails make it easy to add validations to your model classes and allows you to create your own validation methods as well.


1 Answers

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.

like image 157
ipd Avatar answered Sep 19 '22 01:09

ipd