So in rails, if any of the input is not valid, the page returns back to the input page and red errors will show up next to that input_text or textarea. For example, <% validates_presence_of :email %> It will say the error at the top, and the email input text turns into red.
However, when I separately made a valid checking statement in a model, for example, <% def valid_email? TMail::Address.parse(self.email) rescue errors.add("Please type in the correct email address.") end %> 开发者_JS百科It will say the error at the top, but the input_text itself does not turn into red.
How can I manually set the input text to be turn into red??
It should be:
self.errors.add(:email, "Please type in the correct email address.")
try this...
self.errors.messages[:email] = ["your error message"]
精彩评论