I am trying to add rows of input forms from a partial. Some of the fields in the partial have collection_select:
<td><%= label_tag :book_id, t("book") %></td>
<td><%= collection_select :books, "books[:id]", Book.all, :id, :name %></td>
The problem is when I dynamically add rows of this kind only the last one is passed to the controller in the params. I did not pass collection to the partial because it is dynamically added. I would appreciate it if you can help me out with this one.
Its because the param name is being replaced by clones. You can add a counter:
<% (1..10).each do |i| %>
<td><%= collection_select :books, "books[#{i}][:id]", Book.all, :id, :name %></td>
<% end %>
Of course, this is just simple example. Its better to control this counter by JavaScript events.