dimanche 1 novembre 2020

How to stop select statement from overwriting the other if they save to the same column

so I am trying to save one of these select statements depending on another select. I have both of these select statements hidden and if the previous select option is 1 goals is shown. If 2 is selected the budget is shown. But the problem is when I try to set the next value. The last select value overwrites the other. So if I select goals and try to save that value the budget select will overwrite it. What is the best way to stop this from happening?

<div class="form-group" id="goal_attachid" style="display: none;">
<%= form.label :"Select Goal to Attach" %>
   <select name="post[attachid]" id="goal_attachid">
    <option disabled value="" selected hidden>Please Select</option>
    <% Goal.where(user_id:current_user).each do |goal| %>
       <option value=<%= goal.id %>> Goal: <%= goal.title %></option>
    <% end %>
   </select>
  </div>

    <div class="form-group" id="budget_attachid" style="display: none;">
       <%= form.label :"Select Budget to Attach" %>
       <select name="post[attachid]" id="budget_attachid">
        <option disabled value="" selected hidden>Please Select</option>
        <% Budget.where(user_id:current_user).each do |budget| %>
           <option value=<%= budget.id %>> Budget: <%= budget.month %> <%= budget.year %>
        </option>
       <% end %>
  </select>
</div>

Aucun commentaire:

Enregistrer un commentaire