views:

353

answers:

1

I have a nested form, and for the most part it is working great. The only issue that I have is in displaying validiation errors.

Consider the following object relationship: a Project has_many :tasks, a Task has_many :assignments

if a validation error occurs on an assignment, with <%=project_form.error_messages %> It displays Task Assignment Due Date is invalid I would rather it just read Due Date is invalid or Jon's Math Homework Due Date is invalid.

Does this support exist? Do I need to roll my own? Anyone have any ideas?

Thanks!

Jonathan

A: 

In my application those errors didn't has "Task Assignment" part. I don't remember that I had changed something somewhere. You can try writing your own method to display errors. You can get to them using:

@project.errors

or using form builder:

project_form.object.errors

Firstly try to just inspect them:

# in view
<%= @project.errors.inspect %>

It will allow you to take a look on it's structure.

klew
Thanks for the advice, couldn't figure out where the Task Assignment part came from either. So I took your advice and rolled my own. I found that the exposed errors where not sufficient. So I added the following an initializer: `class ActiveRecord::Errors def errors_hash return @errors endend`Worked like a charm.
Jonathan