If I have a model like:
class Person < ActiveRecord::Base
validates_presence_of :name, :login, :email
end
In the view form, if I leave say email empty and submit the form the error message by Rails will be :
email can't be blank.
I am wondering, how can I customize this error message for Rails build-in validation helpers?
I mean I would like :name
, :login
field use the default error message, but only want :email
raise the message like " You have to provide email address
" . How to achieve this?
I am using Rails v2.3.2
Custom error message (default is: "can't be blank").
class Person < ActiveRecord::Base
validates_presence_of :name, :login
validates_presence_of :email, :message => 'your custom messages'
end
http://railsapi.com/doc/v2.3.2/classes/ActiveRecord/Validations/ClassMethods.html#M001871
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.