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
Written by Andrey Koleshko
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#