M
M
Max2016-04-14 18:03:26
Ruby on Rails
Max, 2016-04-14 18:03:26

How to write to the database of several objects from one form?

Hello, there are 100 div blocks on the page (each block is a place in the cinema). When selecting multiple blocks, an array is created in which the id of the blocks is written and sent to the ruby ​​variable. Next, the form for adding records to the database is rendered.

<% if @test_test.present? %>
  <% @test_test.each do |i| %>
    <div class="col-md-6 booking_blocks" id="<%= i %>">
    <button class="close" id="close" value="<%= i %>">×</button>
    <%= form_for(@place) do |f| %>
       <div class="field">
     	<%= f.hidden_field :cinema_id, :value => @film_session.cinema_id %>
        <%= f.label :cinema_name %><br>
        <p><%= @cinema.cinema_name %></p>
      </div>
     	<%= f.hidden_field :film_session_id, :value => @film_session.id %>
     	<%= f.hidden_field :place_number, :value => i %>

      <div class="field">
        <%= f.label :session_name %><br>
        <p><%= @film_session.session_name %></p>
      </div>
      <div class="field">
        <%= f.label :place_number %><br>
        <p><%= i %></p>
      </div>
      <div class="field">
        <%= f.label :status %><br>
        <%= f.check_box :status, class:"form form-control" %>
      </div>
      <br/>
    <% end %>
    </div>
  <% end %>
  <div class="actions">
      <%= submit_tag "Booking", :class => "btn btn-primary" %>
  </div>
<% end %>

The form displays data from the selected blocks
7320d344b64549baad28a8d01aecd8f9.png
Please tell me how to implement the entry into the database of several objects at once from this form by pressing a single submit button.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
g_s_e, 2016-04-14
@g_s_e

stackoverflow.com/questions/25120956/rails-4-neste...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question