Skip to content

Aug 15 / Rupak Ganguly

Tip: has_one and nested form/attributes

Although, the usage of nested forms with has_many associations is well documented, I found that especially the call ..build that works for has_many associations do not work for has_one associations. For the code to work for has_one associations, use this instead:
.build_
E.g book.build_author where book has_one association to author.

Hope this helps.

2 Comments

leave a comment
  1. Pedro Coelho / Sep 8 2009

    Yes. It actually helped a lot. Thanks for the heads up!

  2. Rupak Ganguly / Sep 9 2009

    @Pedro,
    Glad it helped you. I try to post things that I got stuck and scratched my head. Good luck!

Leave a Comment