Q: Save Question(s) form with one submit button In my rails app I have a questions view that renders all the questions in a poll. I want to make sure that all the questions rendered can be submitted using 1 submit button.
If that's not possible, how can I render one question after another until there are no more quesitons?
The front-end code goes:
poll_question.html.erb:
  <% @poll.questions.each do |qst| %>
              <%= render "questions" , qst: qst%>
              <p style="color: red"><%= notice %></p>
              <hr>
            <% end %>

Render partial _questions.html.erb:
<%= form_with model: qst.question_results.build, url: question_question_results_path(qst) do |f| %>
  <% qst_type =  qst.poll.voting_type %>
  <% option_length = qst.options.count %>
  
  <%= f.hidden_field :question_id, value: qst.id %>
  <%= f.hidden_field :option_id, value: qst.options.first.id %> 

  <h3> <%= qst.title %></h3>
    <h6> <%= qst.description %> </h6>
    <ul>
      <% qst.options.each do |option| %>
            <%= f.fields_for :question_result_ranks, f.object.question_result_ranks.build do |rank_f| %>
              <%= rank_f.hidden_field :option_id, value: option.id %>
              <%= option.title %> 
              <%= rank_f.select :rank,  options_for_select((1..option_length).step(1)) %><br>
            <% end %>
    <% end %>
    </ul>
    
  <div>
    <%= f.submit "Save Answer" %>
  </div>

<% end %>


Here is my routes.rb
resources :users do
    resources :polls 
        # Questions
        resources :questions, shallow: true do
        resources :options
        resources :question_results
        patch "/create_question_results", to: "questions#create_question_results", as: "create_question_results"
        end
    end

Edit: These views are not rendered under the Poll and Question Controller, They are rendered under the session module which has no relationships in the model.

A: If you want to submit all the questions with one click, you should use a nested form.
Main template poll_question.html.erb:
<%= form_with model: @poll do |form| %>
  <%= form.fields_for :questions do |f| %>
    # This block renders a collection of partials.
    <%= render 'question', f: %>
  <% end %>
<%= form.submit 'Save' %>
<% end %>

Question form _quiestion.html.erb:
<% qst = f.object %>

<% qst_type =  qst.poll.voting_type %>
<% option_length = qst.options.count %>
<%= f.hidden_field :question_id, value: qst.id %>
<%= f.hidden_field :option_id, value: qst.options.first.id %>
<h3> <%= qst.title %></h3>
<h6> <%= qst.description %> </h6>
<ul>
  <% qst.options.each do |option| %>
    <%= f.fields_for :question_result_ranks, f.object.question_result_ranks.build do |rank_f| %>
      <%= rank_f.hidden_field :option_id, value: option.id %>
      <%= option.title %>
      <%= rank_f.select :rank,  options_for_select((1..option_length).step(1)) %><br>
    <% end %>
  <% end %>
</ul>

And don't forget to add accepts_nested_attributes_for :questions in your poll model.
