vendredi 3 mai 2019

How to use HTML ID in a ruby if statement condition

Im trying to render a form depending on which checkbox has been ticked. I want to use an if statement with the checkbox's id in the condition, but rails is throwing up an error 'undefined method tab1. Is there a way to target html in an if statement? thanks

<input id="tab1" type="radio" name="tabs" checked>
  <label class="label-header" for="tab1"> UK Address</label>

  <input id="tab2" type="radio" name="tabs">
  <label class="label-header"for="tab2"> International Address </label>

  <!-- <section id="content1"> -->
        <% if tab1.checked? %>
                <%= f.simple_fields_for :address do |fields| %>
                        <section id="content1">
                        <%= render "address/fields", fields: fields, addressable: addressable %>
                </section>
                <% end %>
          <% else %>
                <%= f.simple_fields_for :address do |fields| %>
                        <section id="content2">
                        <%= render "address/international_fields", fields: fields, addressable: addressable %>
                </section>
                <% end %>
        <% end %>

Aucun commentaire:

Enregistrer un commentaire