开发者

How can I add a red error message for wrong input in the form in rail3?

开发者 https://www.devze.com 2023-01-22 03:30 出处:网络
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.

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"]
0

精彩评论

暂无评论...
验证码 换一张
取 消