Rails 2.3 has a good solution for multi model forms. But there is not much examples of how to use accepts_nested_attributes_for
with has_one
relation.
Assume that we have a Book model which has one Author.
Controller :
View:
No special action is needed for create
method of BooksController, attr_accessible is not necessary for Book model. Just don’t forget to add the second parameter (@book
) of form_for
and build your nested object (@book.build_author).