# Getting nicely formated error page for associated models

**URL:** <https://www.ruby-forum.com/t/getting-nicely-formated-error-page-for-associated-models/85766>\
**Category:** Rails\
**Created:** [February 16, 2007, 4:06am UTC](https://www.ruby-forum.com/t/getting-nicely-formated-error-page-for-associated-models/85766 "2007-02-16T04:06:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [February 16, 2007, 4:06am UTC](https://www.ruby-forum.com/t/getting-nicely-formated-error-page-for-associated-models/85766/1 "2007-02-16T04:06:44Z")

</div>

I have a question regarding reporting of errors for models which  
contain other models.

For example, if I have a User model which contains a Comments  
collection, and I am not able to see any errors encountered when  
validating the comments.

So if I do something like the following to append a new comment:

user = User.find(id)

comment = Comment.new(:comment =\> params[:comment\_text],  
:user\_id =\> id)

user.comments \<\< comment  
user.save!

When I do this, with an empty :comment\_text string, I get an exception  
(coming from a validates\_length\_if associated with the Comment  
model).

My question is, how can I get this to show on the form via \<%=  
error\_messages\_for… %\>, nicely formated instead of an application  
exception error message?

At the moment I have a \<%= error\_messages\_for :user %\>, which results  
in a nicely formated page showing any validation errors for User. But  
not if an empty comment is added to the user’s comments collection.

Any help would be greatly appreciated.

Cheers,  
Diego

---

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [February 16, 2007, 8:18am UTC](https://www.ruby-forum.com/t/getting-nicely-formated-error-page-for-associated-models/85766/2 "2007-02-16T08:18:31Z")

</div>

Hi Diego,

take a look at [http://railsforum.com/viewtopic.php?id=717](http://railsforum.com/viewtopic.php?id=717) , that should  
provide a solution to your problem.

Kind regards,

## Nick S.

> **[Ruby on Rails hosting companies - Compare, review and find your next ROR host](https://www.railshostinginfo.com)**
>
> Are you looking for a good and reliable Ruby on Rails hosting company? We have lined them up so you can easily compare and review them.

Compare Rails hosting companies

---

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [February 21, 2007, 3:43am UTC](https://www.ruby-forum.com/t/getting-nicely-formated-error-page-for-associated-models/85766/3 "2007-02-21T03:43:41Z")

</div>

Nick, thanks for the reply. Appreciate it.

On Feb 16, 6:18 pm, Nick S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
