app/views/hunter_backstories/_form.html.erb
<%= form_with(model: hunter_backstory_form_model(hunter_backstory), local: true) do |form| %>
<%= render 'layouts/errors', errors: hunter_backstory.errors %>
<%= form.hidden_field :hunter_id %>
<%= form.hidden_field :playbook_id %>
<h5 class="title is-5">Configure backstory of <%= hunter_backstory.playbook.name %></h5>
<% hunter_backstory.backstory&.headings&.each do |heading| %>
<h6 class="title is-6"><%= heading[:name] %> (<%= heading[:count] %>)</h6>
<% (0...heading[:count].to_i).each do |index| %>
<% if heading[:options] %>
<%= form.select("choice_#{heading[:name]}_#{index}",
heading[:options],
{
selected: hunter_backstory.choices&.dig(heading[:name], index) || nil
},
{
name: "hunter_backstory[choices][#{heading[:name]}][]"
}) %>
<% end %>
<% end %>
<% end %>
<div class="actions">
<%= form.submit class: 'button is-primary' %>
</div>
<% end %>