RubyFlow The Ruby and Rails community linklog

Awesome Nested Fields for Rails

In Rails, you can create forms that have fields from nested models. For example, if a person has many phone numbers, you can easily create a form that receives data from the person and from a fixed number of phones. However, when you want to allow the person to insert multiple, indefinite phones, you’re in trouble: it’s much harder than it should be. Well, not anymore. Check the awesome demo or the project code. =)

Comments

The code does not work in the demo. The place drop down does not change to the saved value if editing the form. E.g make a phone number work. Save it and then edit it - the drop down says Home still :(

I got the same problem. But it’s pretty easy to fix it. Replace <%= f.select :place, options_for_select([‘Home’, ‘Work’, ‘Other’]) %> with <%= f.select :place, [‘Home’, ‘Work’, ‘Other’] %>.

I did a pull request on github to fix it.

BTW, awesome work :)

Nice Anderson. Pull request applied and app updated. Thanks!

I mean this as a genuine question and not a criticism, but how does this differ from Ryan Bates’ nested_form gem? https://github.com/ryanb/nested_form

In fact, I started this project one year ago for an app that uses this nested fields a lot. In that time, I looked for some gems, including nested_form, but we need more things, like performing some validations before inserting fields and manipulate them dynamically. So the main difference is that awesome_nested_fields includes callbacks and an API for the JS. Another minor difference is that awesome_nested_fields focus more on the client side. For example: there is no methods to create an add or remove link. But I’m really grateful to Ryan Bates for his screencasts, specially the two about Nested Forms, that are the base of this gem. =)

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in