Ask A Question

Notifications

You’re not receiving notifications from this thread.

Accepts_nested_attributes vs the regular way.

John Magee asked in Rails

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?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.