Note that there are some explanatory texts on larger screens.

plurals
  1. POcheck_box always submitting as 0
    primarykey
    data
    text
    <p>The data goes into the database, but it's always submitting the :location as 0. How do I avoid this? I want the :location to submit the checked value. </p> <p>Also, would it be easier to use simple_form instead of doing it like this?</p> <p><strong>Here's the partial:</strong></p> <pre><code>&lt;%= form_for(@offering) do |f| %&gt; &lt;%= render 'common/form_errors', object: @offering %&gt; &lt;%= f.label :description, "Description:" %&gt; &lt;%= f.text_field :description %&gt; &lt;%= f.label :location, "Where?" %&gt; &lt;%= check_box("offering", :location, {}, "Alphabet City") %&gt;Alphabet City &lt;%= check_box("offering", :location, {}, "Battery Park") %&gt;Battery Park &lt;%= check_box("offering", :location, {}, "Chelsea") %&gt;Chelsea &lt;%= check_box("offering", :location, {}, "Chinatown") %&gt;Chinatown &lt;%= f.submit "Post your offering" %&gt; &lt;% end %&gt; </code></pre> <p><strong>Here's the html it produces:</strong></p> <pre><code> &lt;form accept-charset="UTF-8" action="/offerings" class="new_offering" id="new_offering" method="post"&gt;&lt;div style="margin:0;padding:0;display:inline"&gt;&lt;input name="utf8" type="hidden" value="✓"&gt;&lt;input name="authenticity_token" type="hidden" value="L6oao6csQJ9TIRpEKG4BAzj3uH6FUMr9YmDYXx2HbFg="&gt;&lt;/div&gt; &lt;label for="offering_description"&gt;Description:&lt;/label&gt; &lt;input id="offering_description" name="offering[description]" size="30" type="text"&gt; &lt;label for="offering_location"&gt;Where?&lt;/label&gt; &lt;input name="offering[location]" type="hidden" value="0"&gt; &lt;input id="offering_location" name="offering[location]" type="checkbox" value="Alphabet City"&gt;Alphabet City &lt;input name="offering[location]" type="hidden" value="0"&gt; &lt;input id="offering_location" name="offering[location]" type="checkbox" value="Battery Park"&gt;Battery Park &lt;input name="offering[location]" type="hidden" value="0"&gt; &lt;input id="offering_location" name="offering[location]" type="checkbox" value="Chelsea"&gt;Chelsea &lt;input name="offering[location]" type="hidden" value="0"&gt; &lt;input id="offering_location" name="offering[location]" type="checkbox" value="Chinatown"&gt;Chinatown &lt;input name="commit" type="submit" value="Post your offering"&gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload