I',m trying to achieve a simple nested model form in Rails 4. This is probably something very simple, but just can't figure it out.
So I have an edit view, in which I create the nested fields:
<%= f.fields_for :bankaccounts do |bankaccount| %>
<%= render 'bankaccount_fields', :f => bankaccount %>
<% end %>
These work fine and even the link:
<%= link_to_add_association 'add', f, :bankaccounts , :class => "link"%>
works fine. The fields appear as they should when clicked.
The real problem is, that when I submit the form. It doesn't send the parameters back to web server which have been inputted into these added fields. (Can't see them anywhere in the webrick console) The form only submits the old bankaccount parameters as it should:
"bankaccounts_attributes"=>{"0"=>{"iban"=>"121221", "swift"=>"121212", "id"=>"3"}, "1"=>{"iban"=>"33333", "swift"=>"33333", "id"=>"9"}, "2"=>{"iban"=>"121212", "swift"=>"211212", "id"=>"10"}
Above attributes should contain four bank accounts.
FWIW: Turbolinks is also disabled.
EDIT: Here's the code from bankaccount_fields partial:
<div id="tilit">
<div class="area-form">
<div class="col">
<div class="box-row">
<label for="iban" class="label">Iban</label>
<div class="input-row no-italic">
<%= f.text_field :iban, :id => "iban", :class => "input-text" %>
</div>
</div>
</div>
<div class="col">
<div class="box-row">
<label for="swift" class="label">Swift</label>
<div class="input-row no-italic">
<%= f.text_field :swift, :id => "swift", :class => "input-text" %>
</div>
</div>
</div>
</div>
EDIT: Debugger outputs reg. parameters:
(rdb:2) @_params {"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"181xsndllcPmpvpMaDi70IXh8SpaSYxs0eiSo19qwfI=", "producer"=>{"name"=>"Anne", "RH_nro"=>"", "ytunnus"=>"", "prepaymentpercentage"=>"", "streetaddress"=>"", "zip"=>"", "city"=>"", "www"=>"", "bankaccounts_attributes"=>{"0"=>{"iban"=>"13123123", "swift"=>"121212", "id"=>"3"}, "1"=>{"iban"=>"33333", "swift"=>"33333", "id"=>"9"}, "2"=>{"iban"=>"121212", "swift"=>"211212", "id"=>"10"}}}, "commit"=>"TALLENNA", "action"=>"update", "controller"=>"producers", "id"=>"54"}
Should contain one more bankaccount_attributes record, but only contains the ones which are not dynamically added.
I've been scratching my head for hours now, so any help would be greatly appreciated.
Also sorry if the question is formed badly, this is my first :)
debuggerstatement in your controller action. When you reach the breakpoint you can look at what is inparams[:producer][:bankaccounts_attributes]. If the right values appear there, then check out the suggestions from @Rich Peck below.