Skip to content

Instantly share code, notes, and snippets.

@deathbob
Created May 28, 2009 21:47
Show Gist options
  • Save deathbob/119603 to your computer and use it in GitHub Desktop.
Save deathbob/119603 to your computer and use it in GitHub Desktop.
Holy fuck is getting a has_one to work with nested forms a pain in the dick.
useful links if you're working on this http://www.pixellatedvisions.com/2009/03/18/rails-2-3-nested-model-forms-and-nil-new-record
and especially
#
Michał Czyż – February 14, 2009 @ 02:23 PM
i’ve got this same problem, like you Gastón Ramos, when i write something like this:
- f.fields_for :steps do |step|
after some combination, i figured out, that adding ‘_attributes’ suffix in form builder helps
from http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes
THIS will shit on your parade
<% person_form.fields_for :child do |child_form| %>
THIS will make your day
<% person_form.fields_for :child_attributes do |child_form| %>
SIMILARLY
<% f.fields_for :address_attributes do |a| %>
is what you want.
this too has much good information
http://railsforum.com/viewtopic.php?pid=97202
I'll try and get into the subtlties of the fields_for :address vs fields_for :address_attributes some time, but for now just glad it's working. If anybody does read this and knows what the hell is going on, please enlighten me.
dear rails masters, WTF??????????????????
If google picks this up, here's what you have to do.
If you're reading this you may have gotten a
ActiveRecord::AssociationTypeMismatch *MODEL* expected, got HashWithIndifferentAccess *params[:your nested form]*
assuming you managed to create your model in a new action
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment