Question

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 %> 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??

Was it helpful?

Solution

It should be:

self.errors.add(:email, "Please type in the correct email address.")

OTHER TIPS

try this...

self.errors.messages[:email] = ["your error message"]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top