# model validators

**URL:** <https://discuss.rubyonrails.org/t/model-validators/3628>\
**Category:** rubyonrails-talk\
**Created:** [October 26, 2006, 7:33am UTC](https://discuss.rubyonrails.org/t/model-validators/3628 "2006-10-26T07:33:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chad](https://avatars.discourse-cdn.com/v4/letter/c/ecccb3/32.png) [@Chad](https://discuss.rubyonrails.org/u/Chad)\
**Post date:** [October 26, 2006, 7:33am UTC](https://discuss.rubyonrails.org/t/model-validators/3628/1 "2006-10-26T07:33:34Z")

</div>

If i run two validators on the same model attribute and they both fail, two messages show. Is there any way to only show the first failure message?

---

<div class="post-metadata">

**Author:** ![Duplex](https://avatars.discourse-cdn.com/v4/letter/d/96bed5/32.png) [@Duplex](https://discuss.rubyonrails.org/u/Duplex)\
**Post date:** [October 26, 2006, 9:05am UTC](https://discuss.rubyonrails.org/t/model-validators/3628/2 "2006-10-26T09:05:40Z")

</div>

Instead of using the pre-formatted error\_messages\_for() you could create your own helper ...

def my\_error\_messages\_for error\_attrs = Object.errors.each do |attr,msg| &nbsp;&nbsp;unless errory\_attrs.include? attr &nbsp;&nbsp;&nbsp;...define your message and stuff... &nbsp;&nbsp;&nbsp;error\_attrs \<\< attr # add the attribute to the array of already processed attribute &nbsp;&nbsp;end end end

that code is in no way complete and not guaranteed to be correct ... for an idea how to do the "define your error messages and stuff" part, have a look at the source of error\_messages\_for() in the Rails API docs

---

<div class="post-metadata">

**Author:** ![Duplex](https://avatars.discourse-cdn.com/v4/letter/d/96bed5/32.png) [@Duplex](https://discuss.rubyonrails.org/u/Duplex)\
**Post date:** [October 26, 2006, 9:13am UTC](https://discuss.rubyonrails.org/t/model-validators/3628/3 "2006-10-26T09:13:53Z")

</div>

just had a look at my above code and wanted to make clear that the whole method is NOT gonna work like this, it has no return value, the def line is missing the variables it should get passed etc ... but i think you get the idea ...
