Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

error_messages on accepts_nested_attributes_for and autosaved associations

#3002

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.

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

State: duplicate
Milestone: none
Assigned to: Eloy Duran Eloy Duran
Importance: none

Activity

  1. Eloy Duran
    Eloy Duran
    • Assigned user set to Eloy Duran
    • State changed from new to duplicate

    Please see the following ticket which should probably allow you to cleanly handle this: #2904 Avoid copying errors from child to parent on autosave

    August 7th, 2009 @ 10:52 AM