This project is archived and is in readonly mode.

#3002 ✓duplicate
jonnii

error_messages on accepts_nested_attributes_for and autosaved associations

Reported by jonnii | August 7th, 2009 @ 03:43 AM

I have the following:

class Profile < AR:B

belongs_to :profile_detail
accepts_nested_attributes_for :profile_detail

end

The way I have my views structured means that most of the time a user will be editing their Profile and the ProfileDetail information together, in fact in this case I extracted ProfileDetail from Profile.

The current behavior of the error_message helper is to prepend the association name to any errors that occur when the nested attributes are validated. However, in my case all of the attributes are unique so there's no benefit to having the association name prepended when displaying the errors and it makes the validation errors look a bit weird.

This is primarily a view related change, just like we can specify the object_name for our error_messages I think it should be possible to set the validation message prefix for autosaved associations, perhaps using a mapping:

<%= f.error_messages :error_prefix => { :funky_association_with_massive_name => 'cake' } %>

or by flattening them all:

<%= f.error_messages :flatten_errors_on_associations => true %>

I'd be happy to attempt to create a patch for this as I think it serves a genuine purpose. I await your feedback.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Referenced by

Pages