문제

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

도움이 되었습니까?

해결책

It should be:

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

다른 팁

try this...

self.errors.messages[:email] = ["your error message"]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top