xeroshogun
xeroshogun

Reputation: 1092

Rails simple-form with multiple instances of the same object

I am trying to create a rails form using simple form that uses nested resources. However, I want to be able to submit multiple instances of the associated resource. Example below will probably explain it better.

<div class="tab-pane active" id="reminder">
    <%= simple_form_for @collection, html: {multipart: true}, url: collection_index_path do |m| %>

        <%= render partial: "collection/tabs/reminder", locals: { :m => m } %>
    </div>

-inside partial

<% 9.times do |j|%>
    <div class="tab-pane" id="<%= j %>">
        <%= m.simple_fields_for :reminder do |p| %>
            <%= p.input :heading %>
            <%= p.input :message %>
        <% end %>           
    </div>

There is a tabbed pane in which the user can click through 9 tabs to set up to 9 reminders, all should be associated with a collection (collection model accepts nested attributes for reminder). However, the way I have it setup now, the controller only gets what was set in the last reminder in the params. Anyway ideas would be appreciated.

Upvotes: 2

Views: 2076

Answers (1)

Gena  Shumilkin
Gena Shumilkin

Reputation: 723

There must be some way to distinguish tabs before submitting to controller. And i think answer might be here. i.e. it looks like this:

<% 9.times do |j|%>
    <div class="tab-pane" id="<%= j %>">
        <%= m.simple_fields_for :reminders do |p| %>
           <%= p.input :heading %>
           <%= p.input :message %>
        <% end %>
    </div>
<% end %>

Upvotes: 2

Related Questions