Forum: Ruby on Rails Getting nicely formated error page for associated models.

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
05bf52a3e873f6847b05536a99bec4ad?d=identicon&s=25 Diego (Guest)
on 2007-02-16 04:06
(Received via mailing list)
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 = => params[:comment_text],
                    :user_id => id)

user.comments << comment!

When I do this, with an empty :comment_text string, I get an exception
(coming from a validates_length_if associated with the Comment

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.

91308e9bc88cb069fd1bcf88e910d042?d=identicon&s=25 Nick Snels (nicksnels)
on 2007-02-16 08:18
Hi Diego,

take a look at , that should
provide a solution to your problem.

Kind regards,

Nick Snels
Compare Rails hosting companies
05bf52a3e873f6847b05536a99bec4ad?d=identicon&s=25 Diego (Guest)
on 2007-02-21 03:43
(Received via mailing list)
Nick, thanks for the reply. Appreciate it.

On Feb 16, 6:18 pm, Nick Snels <>
This topic is locked and can not be replied to.