# Nested Models & Error Validation

**URL:** <https://www.ruby-forum.com/t/nested-models-error-validation/167915>\
**Category:** Rails\
**Created:** [May 13, 2009, 11:28pm UTC](https://www.ruby-forum.com/t/nested-models-error-validation/167915 "2009-05-13T23:28:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![willclarkdesigns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/85f322/32.png) [@willclarkdesigns](https://www.ruby-forum.com/u/willclarkdesigns)\
**Post date:** [May 13, 2009, 11:28pm UTC](https://www.ruby-forum.com/t/nested-models-error-validation/167915/1 "2009-05-13T23:28:13Z")

</div>

I have two models: User and MemberProfile

class MemberProfile \< ActiveRecord::Base  
belongs\_to :user  
validates\_presence\_of :name  
#…  
end

class User \< ActiveRecord::Base  
has\_one :member\_profile  
validates\_presence\_of :email  
accepts\_nested\_attributes\_for :member\_profile  
#…  
end

My view looks like:

\<%= error\_messages\_for :user %\>  
\<% form\_for :user, :url =\> users\_path do |f| %\>

\<%= f.label :email %\> \<%= f.text\_field :email %\>

\<% f.fields\_for :member\_profile do |mp| %\>

\<%= mp.label :name %\> \<%= mp.text\_field :name %\>

\<% end %\>  
\<% end %\>

The error validations are working correctly. It is checking for both  
email and name on both objects. The error list is correctly populating  
the error\_messages\_for call. The two problems I’m having are:

1. I’d like the errors for the MemberProfile object to be displayed as  
“Name can’t be…” instead of “Member profile name can’t be…” in  
div#errorExplanation
2. The MemberProfile fields are not receiving the div.fieldWithErrors

Is there a way to deal with these two issues?

Thanks
