ana
ana

Reputation: 485

Nested forms Ruby on Rails

I have a model Person and a model Option. Option belongs_to person, and Person has_many options. In the form for creating a new Person I want to be able to add several Options before you save the Person. What is the best way to do this?

Upvotes: 1

Views: 100

Answers (3)

Greg Lafrance
Greg Lafrance

Reputation: 758

You might find my question, which was answered, and for which I post more or less complete solution files for, to be of use with nested associations:

Why submitting to wrong action when implementing "favorites", modeled after Michael Hartl's following / followers in Rails Tutorial

Upvotes: 0

ezkl
ezkl

Reputation: 3861

It isn't necessarily the best solution, but Ryan Bates' nested_form library makes managing dynamic form elements for associated models quite easy. Easy to install and the usage directions in the README sound like they cover your basic case.

Upvotes: 0

Aayush Khandelwal
Aayush Khandelwal

Reputation: 1071

Go for rails casts episode 196 and 197 . they have detailed explation and are the best to implement this kind of functionality

http://railscasts.com/episodes/196-nested-model-form-part-1
http://railscasts.com/episodes/197-nested-model-form-part-2

Upvotes: 1

Related Questions