WideFix tech post

Build associations automatically in fields_for helper

Assume you have code in your project like this:

form_for :company do |f|
  f.fields_for(:user, f.object.user || f.object.build_user) do |ff|
    ff.text_field :name

With get_or_build gem you are able to translate this code to code like this:

form_for :company do |f|
  f.fields_for(:user, :build_association => true) do |ff|
    ff.text_field :name

Hope you will enjoy this gem! Thank you for your attention!

Are you seeking assistance with Ruby on Rails development?

Read also