Last Updated: February 25, 2016
·
799
· ka8725

Build associations automatically in fields_for helper

Checkout my gem: https://github.com/ka8725/get_or_build
It helps to avoid boring code in fields_foe helper 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 gem getorbuild you can just pass one option and that's it:

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