Ruby on Rails/Javascript - Form_for is not evaluating to true, defaults to false












0















So I have a simple form for people to fill out if they want to request items, either delivered or shipped overseas. They answer a simple Yes or No.



Question: What should I be adding to this code so the option of Yes does evaluate to True, and the option No evaluated to false, and is not defaulting to False for the "Item Delivered" question.



NOTE: I have left code out intentionally, assume Ruby on Rails does work correctly as I may have left out <% end %> or other code bits.



This is the code, with stuff omitted:



new.html.erb



<%= form_for @items do |f| %>
<div class="form-group">
<%= f.label :"Pick up item?" %><br />
<div class="form-inline">
<div class="radio inline ">
<%= f.label :pickup, "Yes", :value => "Yes" %>
<%= f.radio_button :pickup, true%>
</div>
<div class="radio inline ">
<%= f.label :pickup, "No", :value => "No" %>
<%= f.radio_button :pickup, false, :checked => true %>
</div>
</div>
</div>

<div class="form-group">
<%= f.label :"Item delivered?" %><br />
<div class="form-inline">
<div class="radio inline requestOption optionDropoff">
<%= f.label :delivered, "Yes", :value => "Yes" %>
<%= f.radio_button :delivered, true%>
</div>
<div class="radio inline requestOption">
<%= f.label :delivered, "No", :value => "No" %>
<%= f.radio_button :delivered, false, :checked => true %>
</div>
</div>
</div>

<div id="itemRequestAddress" style="display: none">
<%= f.label :"Delivery address" %>
<div class="form-group form-inline" id="itemAddress">
<%= text_field(:item, :address, :class => "form-control", :placeholder => "Delivery Address", :style => "width: 100%") %>
</div>
</div>

<script type="text/javascript">
$(".requestOption").on("change", function(){
$("#itemRequestAddress").toggle($(this).hasClass("optionDropoff"));
});
</script>


show.html.erb



    <tr>
<td> Pick up. </td>
<td> <% if @item.pickup %>
<%= 'Yes' %>
<% else %>
<%= 'No' %>
<% end %>
</td>
</tr>

<tr>
<td> Item delivered. </td>
<td> <% if @item.delivered %>
<%= 'Yes' %>
<% else %>
<%= 'No' %>
<% end %>
</td>
</tr>

<tr>
<td> Delivery Address </td>
<td>
<%= @request_item.address %>
</td>
</tr>


So Pick up option does evaluate to either True or False, when either the Yes or No option is chosen. When I do Delivery, it always evaluations to No, regardless of whether I choose Yes or No. What have I done wrong here?










share|improve this question



























    0















    So I have a simple form for people to fill out if they want to request items, either delivered or shipped overseas. They answer a simple Yes or No.



    Question: What should I be adding to this code so the option of Yes does evaluate to True, and the option No evaluated to false, and is not defaulting to False for the "Item Delivered" question.



    NOTE: I have left code out intentionally, assume Ruby on Rails does work correctly as I may have left out <% end %> or other code bits.



    This is the code, with stuff omitted:



    new.html.erb



    <%= form_for @items do |f| %>
    <div class="form-group">
    <%= f.label :"Pick up item?" %><br />
    <div class="form-inline">
    <div class="radio inline ">
    <%= f.label :pickup, "Yes", :value => "Yes" %>
    <%= f.radio_button :pickup, true%>
    </div>
    <div class="radio inline ">
    <%= f.label :pickup, "No", :value => "No" %>
    <%= f.radio_button :pickup, false, :checked => true %>
    </div>
    </div>
    </div>

    <div class="form-group">
    <%= f.label :"Item delivered?" %><br />
    <div class="form-inline">
    <div class="radio inline requestOption optionDropoff">
    <%= f.label :delivered, "Yes", :value => "Yes" %>
    <%= f.radio_button :delivered, true%>
    </div>
    <div class="radio inline requestOption">
    <%= f.label :delivered, "No", :value => "No" %>
    <%= f.radio_button :delivered, false, :checked => true %>
    </div>
    </div>
    </div>

    <div id="itemRequestAddress" style="display: none">
    <%= f.label :"Delivery address" %>
    <div class="form-group form-inline" id="itemAddress">
    <%= text_field(:item, :address, :class => "form-control", :placeholder => "Delivery Address", :style => "width: 100%") %>
    </div>
    </div>

    <script type="text/javascript">
    $(".requestOption").on("change", function(){
    $("#itemRequestAddress").toggle($(this).hasClass("optionDropoff"));
    });
    </script>


    show.html.erb



        <tr>
    <td> Pick up. </td>
    <td> <% if @item.pickup %>
    <%= 'Yes' %>
    <% else %>
    <%= 'No' %>
    <% end %>
    </td>
    </tr>

    <tr>
    <td> Item delivered. </td>
    <td> <% if @item.delivered %>
    <%= 'Yes' %>
    <% else %>
    <%= 'No' %>
    <% end %>
    </td>
    </tr>

    <tr>
    <td> Delivery Address </td>
    <td>
    <%= @request_item.address %>
    </td>
    </tr>


    So Pick up option does evaluate to either True or False, when either the Yes or No option is chosen. When I do Delivery, it always evaluations to No, regardless of whether I choose Yes or No. What have I done wrong here?










    share|improve this question

























      0












      0








      0








      So I have a simple form for people to fill out if they want to request items, either delivered or shipped overseas. They answer a simple Yes or No.



      Question: What should I be adding to this code so the option of Yes does evaluate to True, and the option No evaluated to false, and is not defaulting to False for the "Item Delivered" question.



      NOTE: I have left code out intentionally, assume Ruby on Rails does work correctly as I may have left out <% end %> or other code bits.



      This is the code, with stuff omitted:



      new.html.erb



      <%= form_for @items do |f| %>
      <div class="form-group">
      <%= f.label :"Pick up item?" %><br />
      <div class="form-inline">
      <div class="radio inline ">
      <%= f.label :pickup, "Yes", :value => "Yes" %>
      <%= f.radio_button :pickup, true%>
      </div>
      <div class="radio inline ">
      <%= f.label :pickup, "No", :value => "No" %>
      <%= f.radio_button :pickup, false, :checked => true %>
      </div>
      </div>
      </div>

      <div class="form-group">
      <%= f.label :"Item delivered?" %><br />
      <div class="form-inline">
      <div class="radio inline requestOption optionDropoff">
      <%= f.label :delivered, "Yes", :value => "Yes" %>
      <%= f.radio_button :delivered, true%>
      </div>
      <div class="radio inline requestOption">
      <%= f.label :delivered, "No", :value => "No" %>
      <%= f.radio_button :delivered, false, :checked => true %>
      </div>
      </div>
      </div>

      <div id="itemRequestAddress" style="display: none">
      <%= f.label :"Delivery address" %>
      <div class="form-group form-inline" id="itemAddress">
      <%= text_field(:item, :address, :class => "form-control", :placeholder => "Delivery Address", :style => "width: 100%") %>
      </div>
      </div>

      <script type="text/javascript">
      $(".requestOption").on("change", function(){
      $("#itemRequestAddress").toggle($(this).hasClass("optionDropoff"));
      });
      </script>


      show.html.erb



          <tr>
      <td> Pick up. </td>
      <td> <% if @item.pickup %>
      <%= 'Yes' %>
      <% else %>
      <%= 'No' %>
      <% end %>
      </td>
      </tr>

      <tr>
      <td> Item delivered. </td>
      <td> <% if @item.delivered %>
      <%= 'Yes' %>
      <% else %>
      <%= 'No' %>
      <% end %>
      </td>
      </tr>

      <tr>
      <td> Delivery Address </td>
      <td>
      <%= @request_item.address %>
      </td>
      </tr>


      So Pick up option does evaluate to either True or False, when either the Yes or No option is chosen. When I do Delivery, it always evaluations to No, regardless of whether I choose Yes or No. What have I done wrong here?










      share|improve this question














      So I have a simple form for people to fill out if they want to request items, either delivered or shipped overseas. They answer a simple Yes or No.



      Question: What should I be adding to this code so the option of Yes does evaluate to True, and the option No evaluated to false, and is not defaulting to False for the "Item Delivered" question.



      NOTE: I have left code out intentionally, assume Ruby on Rails does work correctly as I may have left out <% end %> or other code bits.



      This is the code, with stuff omitted:



      new.html.erb



      <%= form_for @items do |f| %>
      <div class="form-group">
      <%= f.label :"Pick up item?" %><br />
      <div class="form-inline">
      <div class="radio inline ">
      <%= f.label :pickup, "Yes", :value => "Yes" %>
      <%= f.radio_button :pickup, true%>
      </div>
      <div class="radio inline ">
      <%= f.label :pickup, "No", :value => "No" %>
      <%= f.radio_button :pickup, false, :checked => true %>
      </div>
      </div>
      </div>

      <div class="form-group">
      <%= f.label :"Item delivered?" %><br />
      <div class="form-inline">
      <div class="radio inline requestOption optionDropoff">
      <%= f.label :delivered, "Yes", :value => "Yes" %>
      <%= f.radio_button :delivered, true%>
      </div>
      <div class="radio inline requestOption">
      <%= f.label :delivered, "No", :value => "No" %>
      <%= f.radio_button :delivered, false, :checked => true %>
      </div>
      </div>
      </div>

      <div id="itemRequestAddress" style="display: none">
      <%= f.label :"Delivery address" %>
      <div class="form-group form-inline" id="itemAddress">
      <%= text_field(:item, :address, :class => "form-control", :placeholder => "Delivery Address", :style => "width: 100%") %>
      </div>
      </div>

      <script type="text/javascript">
      $(".requestOption").on("change", function(){
      $("#itemRequestAddress").toggle($(this).hasClass("optionDropoff"));
      });
      </script>


      show.html.erb



          <tr>
      <td> Pick up. </td>
      <td> <% if @item.pickup %>
      <%= 'Yes' %>
      <% else %>
      <%= 'No' %>
      <% end %>
      </td>
      </tr>

      <tr>
      <td> Item delivered. </td>
      <td> <% if @item.delivered %>
      <%= 'Yes' %>
      <% else %>
      <%= 'No' %>
      <% end %>
      </td>
      </tr>

      <tr>
      <td> Delivery Address </td>
      <td>
      <%= @request_item.address %>
      </td>
      </tr>


      So Pick up option does evaluate to either True or False, when either the Yes or No option is chosen. When I do Delivery, it always evaluations to No, regardless of whether I choose Yes or No. What have I done wrong here?







      javascript ruby-on-rails ruby






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 3:27









      JamesWuJamesWu

      75111




      75111
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385783%2fruby-on-rails-javascript-form-for-is-not-evaluating-to-true-defaults-to-false%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385783%2fruby-on-rails-javascript-form-for-is-not-evaluating-to-true-defaults-to-false%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          MongoDB - Not Authorized To Execute Command

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

          How to fix TextFormField cause rebuild widget in Flutter