Skip to main content

Accepts_nested_attributes vs the regular way.

Rails • Asked by John Magee

So I've spent the last couple days working with accepts_nested_attributes_for in an effort to understand them (I've never used them before). I've used a variety of sources (GoRails video of course is one of them) and even did some funky stuff where I used fields_for via the show view of the parent. I created a custom route to submit the form so I could get the nested validation errors if they existed. And, for the heck of it I kind of figured out how to do it with AJAX (though, getting flash & errors through AJAX to display seems a bit of a conundrum)

Anyway, I've been thinking about it, and I'm just curious as to how much of an advantage accepts_nested_attributes_for (which I call ANAF to save characters on Twitter ;) ) is over the standard <%= form_for [@parent, @parent.children.new] do |f| %> method. I mean are they used in conjunction depending on your need, or do you only use ANAF for stuff you'd only want worked on on the pages that display the parent form?

(And oh yeah, is there any difference between .build and .new?


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.