# Expand errors of sub-object

**URL:** <https://www.ruby-forum.com/t/expand-errors-of-sub-object/115901>\
**Category:** Rails\
**Created:** [September 30, 2007, 1:38am UTC](https://www.ruby-forum.com/t/expand-errors-of-sub-object/115901 "2007-09-30T01:38:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JSPablo\_FernSSSSnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@JSPablo\_FernSSSSnd](https://www.ruby-forum.com/u/JSPablo_FernSSSSnd)\
**Post date:** [September 30, 2007, 1:38am UTC](https://www.ruby-forum.com/t/expand-errors-of-sub-object/115901/1 "2007-09-30T01:38:33Z")

</div>

Hello,  
I have two models, let’s call them Company and User. A company  
belongs\_to a  
user and a user has\_one company (for now, may has\_many latter).  
Currently I’m  
using one form to create both a user and a company at the same time, so  
I  
basically do:  
form\_for company  
fields\_for user  
…form…  
and then I do:  
@company = Company.new params[:company]  
@company.user = User.new params[:user]

## The problem is that when I do error reporting with: \<%= error\_messages\_for :company %\> I don’t get detailed field by field errors of users, only “User is invalid”. How can I get detailed user error messages? Thank you.

J. Pablo Fernández [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) ([http://pupeno.com](http://pupeno.com))

---

<div class="post-metadata">

**Author:** ![JSPablo\_FernSSSSnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@JSPablo\_FernSSSSnd](https://www.ruby-forum.com/u/JSPablo_FernSSSSnd)\
**Post date:** [September 30, 2007, 3:30pm UTC](https://www.ruby-forum.com/t/expand-errors-of-sub-object/115901/2 "2007-09-30T15:30:12Z")

</div>

Be sure to call user.valid? in your action if the company fails so that  
the  
error messages for the user is actually generated.

\<%= error\_messages\_for :company, :user %\>
