Is there a way to validates_presence_of only one time? (to skip that validation once the user's been

Posted by GoodGets on Stack Overflow See other posts from Stack Overflow or by GoodGets
Published on 2010-04-02T20:41:09Z Indexed on 2010/04/02 20:43 UTC
Read the original article Hit count: 273

So, I'd like for a user to see an error message if he submits a comment and the :name is blank (typical error message, don't need help with that). However, I'd then like to allow the user to skip that validation once he's been notified that "we like all comments to have a name." So, he submits the comment once, sees the notification, then can submit the form again unchanged if he really doesn't want to add a name, and the validates_presences_of :name is skipped.

But, I'm not sure how to go about doing this. I thought about checking to see where the request is coming from, but after a create, errors are handed off to the "new" action, which is the same as actual "new" comments.

I then thought about checking to see if flash[errors] were present, but that won't work because there are other validations a comment has to pass.

Finally, I thought about trying a

validates_presences_of :name, :unless => :notified

but wasn't sure how to define notified. I honestly hate asking such an open ended question, but wasn't sure where to get started. So, is there a way to just check a certain validation once?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about validation