# Composed\_of Validation - this is a joke right?

**URL:** <https://www.ruby-forum.com/t/composed-of-validation-this-is-a-joke-right/164712>\
**Category:** Rails\
**Created:** [April 4, 2009, 4:18pm UTC](https://www.ruby-forum.com/t/composed-of-validation-this-is-a-joke-right/164712 "2009-04-04T16:18:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jferg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@Jferg](https://www.ruby-forum.com/u/Jferg)\
**Post date:** [April 4, 2009, 4:18pm UTC](https://www.ruby-forum.com/t/composed-of-validation-this-is-a-joke-right/164712/1 "2009-04-04T16:18:43Z")

</div>

I just read

> **[Rails composed\_of validation](http://www.stephenchu.com/2008/05/rails-composedof-validation.html)**
>
> ActiveRecord allows you to declaratively write validations (e.g. validates\_presence\_of ) in any ActiveRecord::Base models. In addition, the...

article… twice. He does a great job, but what I find really ugly  
(so not Rails) is when I want to use ActiveRecord:Validations module  
in my Value Object - I need to “stub out” some of the inner plumbing  
to pretend I am really an ActiveRecord object.

Is this the best way to integrate Value Objects from aggregations into  
Rails validation and error reporting? My googling so far turns up  
more questions than answers.

The docs such as:

> **[ActiveRecord::Aggregations::ClassMethods](https://api.rubyonrails.org/classes/ActiveRecord/Aggregations/ClassMethods.html)**
>
> Active Record implements aggregation through a macro-like class method called composed\_of for representing attributes as value objects.

talk about a lot but not about validation.

Please show me there is a more elegant, DRY, declarative way to  
realize this than lots of custom code or the module inclusion pattern  
written up by Steve C…

Thanks…

---

<div class="post-metadata">

**Author:** ![Jferg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/f4b2a3/32.png) [@Jferg](https://www.ruby-forum.com/u/Jferg)\
**Post date:** [April 4, 2009, 11:52pm UTC](https://www.ruby-forum.com/t/composed-of-validation-this-is-a-joke-right/164712/2 "2009-04-04T23:52:43Z")

</div>

Work around - validate the component fields as they exist in the  
containing class. In some cases this is better for my needs - but in  
other cases it may be not as useful.

It fits the way Rails works and for now is the best I can do.
