# Should I use the validation framework (e.g. add\_to\_base) to pass back multiple data errors that are

**URL:** <https://www.ruby-forum.com/t/should-i-use-the-validation-framework-e-g-add-to-base-to-pass-back-multiple-data-errors-that-are/158185>\
**Category:** Rails\
**Created:** [January 20, 2009, 8:01am UTC](https://www.ruby-forum.com/t/should-i-use-the-validation-framework-e-g-add-to-base-to-pass-back-multiple-data-errors-that-are/158185 "2009-01-20T08:01:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [January 20, 2009, 8:01am UTC](https://www.ruby-forum.com/t/should-i-use-the-validation-framework-e-g-add-to-base-to-pass-back-multiple-data-errors-that-are/158185/1 "2009-01-20T08:01:51Z")

</div>

Hi,

I have an “automation” model with some config data. When it runs it  
looks  
across other models and does some matching, however it also builds up a  
list  
of “duplicate data” type issues identified as part of the routine.

In terms of how I capture this array of duplicate data issues and pass  
to a  
view for display what would Rails best practice suggest? For example:

- use validation framework (e.g. add\_to\_base, and then the helper tags  
to  
display) even though the data is not associated with attributes in the  
model
- extend an application\_error Exception to include an Array
- just use an array to pass back to controller, which stores as an  
instance  
variable (@duplicates) and write custom code to display in view (i.e.  
won’t  
use error/validation tags)

thanks

–  
Greg  
[http://blog.gregnet.org/](http://blog.gregnet.org/)

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [January 21, 2009, 2:10am UTC](https://www.ruby-forum.com/t/should-i-use-the-validation-framework-e-g-add-to-base-to-pass-back-multiple-data-errors-that-are/158185/2 "2009-01-21T02:10:38Z")

</div>

(bump)

On Tue, Jan 20, 2009 at 5:00 PM, Greg H. \<  
removed\_email\_address@domain.invalid\> wrote:

> - extend an application\_error Exception to include an Array

–  
Greg  
[http://blog.gregnet.org/](http://blog.gregnet.org/)

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [January 21, 2009, 2:33am UTC](https://www.ruby-forum.com/t/should-i-use-the-validation-framework-e-g-add-to-base-to-pass-back-multiple-data-errors-that-are/158185/3 "2009-01-21T02:33:27Z")

</div>

I don’t necessarily see what’s wrong with add\_to\_base. Seems somewhat  
logical to me but I don’t really know what you’re attempting to do 🙂

On Tue, Jan 20, 2009 at 7:09 PM, Greg H.

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [January 21, 2009, 3:14am UTC](https://www.ruby-forum.com/t/should-i-use-the-validation-framework-e-g-add-to-base-to-pass-back-multiple-data-errors-that-are/158185/4 "2009-01-21T03:14:25Z")

</div>

I suppose I was questioning whether from a best practice position  
whether  
using Rails input validation framework (focused at the model level), for  
collecting non-severe error messages that cut across a whole controller  
action (e.g. multiple models may be involved), and for which they are  
not  
focused at input validation but rather error that occuring during  
processing, for the purpose of bundling these up and passing to a view  
and  
displaying? hope this makes sense in terms of clarifying my Rails best  
practice question.

On Wed, Jan 21, 2009 at 11:32 AM, Brian H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > a view for display what would Rails best practice suggest? For example:
> > 
> > Greg  
> > [http://blog.gregnet.org/](http://blog.gregnet.org/)
> > 
> > >
> 
> >

–  
Greg  
[http://blog.gregnet.org/](http://blog.gregnet.org/)

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [January 21, 2009, 3:21am UTC](https://www.ruby-forum.com/t/should-i-use-the-validation-framework-e-g-add-to-base-to-pass-back-multiple-data-errors-that-are/158185/5 "2009-01-21T03:21:26Z")

</div>

You could always go with the “business logic always goes in models”  
rule, and the easy implementation is to do what you’re doing. Or you  
could build a brand new model with its own errors collection to  
encapsulate what it is you’re doing (presenter pattern?). I don’t  
think there’s really a _best practice_ for this… if you can justify  
the use to yourself based on what business rules you’re trying to  
implement, that may be your best practice. 🙂

My rule is always that NOTHING goes in the controller. A lot of times  
I’ve done an after\_validation callback and shoved stuff into the  
errors.base before. Done stuff with cc processing that way too.

I’d love to hear from others on this too.

On Tue, Jan 20, 2009 at 8:13 PM, Greg H.
