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!

Discover Exclusive Ruby/Rails Development Opportunities! Submit Your Details to Receive Timely Job Notifications.

WideFix and Ruby On Rails expertise

At WideFix, we take pride in our expertise and experience. You can trust that our solutions will not harm your business and will always keep your site running smoothly. You can rely on us to provide confident and effective solutions that meet your needs.

Read also