Forum: Ruby on Rails Nested Models & Error Validation

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.
Will C. (Guest)
on 2009-05-14 01:28
I have two models: User and MemberProfile

class MemberProfile < ActiveRecord::Base
  belongs_to :user
  validates_presence_of :name

class User < ActiveRecord::Base
  has_one :member_profile
  validates_presence_of :email
  accepts_nested_attributes_for :member_profile

My view looks like:

<%= error_messages_for :user %>
<% form_for :user, :url => users_path do |f| %>
<p><%= f.label :email %>
<%= f.text_field :email %></p>
<% f.fields_for :member_profile do |mp| %>
<p><%= 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
2. The MemberProfile fields are not receiving the div.fieldWithErrors

Is there a way to deal with these two issues?

This topic is locked and can not be replied to.