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
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.