ruby on rails - check_box always submitting as 0 -
the data goes database, it's submitting :location 0. how avoid this? want :location submit checked value.
also, easier use simple_form instead of doing this?
here's partial:
<%= form_for(@offering) |f| %> <%= render 'common/form_errors', object: @offering %> <%= f.label :description, "description:" %> <%= f.text_field :description %> <%= f.label :location, "where?" %> <%= check_box("offering", :location, {}, "alphabet city") %>alphabet city <%= check_box("offering", :location, {}, "battery park") %>battery park <%= check_box("offering", :location, {}, "chelsea") %>chelsea <%= check_box("offering", :location, {}, "chinatown") %>chinatown <%= f.submit "post offering" %> <% end %>
here's html produces:
<form accept-charset="utf-8" action="/offerings" class="new_offering" id="new_offering" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="authenticity_token" type="hidden" value="l6oao6csqj9tirpekg4bazj3uh6fumr9ymdyxx2hbfg="></div> <label for="offering_description">description:</label> <input id="offering_description" name="offering[description]" size="30" type="text"> <label for="offering_location">where?</label> <input name="offering[location]" type="hidden" value="0"> <input id="offering_location" name="offering[location]" type="checkbox" value="alphabet city">alphabet city <input name="offering[location]" type="hidden" value="0"> <input id="offering_location" name="offering[location]" type="checkbox" value="battery park">battery park <input name="offering[location]" type="hidden" value="0"> <input id="offering_location" name="offering[location]" type="checkbox" value="chelsea">chelsea <input name="offering[location]" type="hidden" value="0"> <input id="offering_location" name="offering[location]" type="checkbox" value="chinatown">chinatown <input name="commit" type="submit" value="post offering"> </form>
so figured out.
the hidden inputs how on ride checkboxes.
so instead of check_box, i'm using check_box_tag this:
<%= check_box_tag("offering[location]", "alphabet city") %>alphabet city <%= check_box_tag("offering[location]", "battery park") %>battery park <%= check_box_tag("offering[location]", "chelsea") %>chelsea <%= check_box_tag("offering[location]", "chinatown") %>chinatown
instead of:
<%= check_box("offering", :location, {}, "alphabet city") %>alphabet city <%= check_box("offering", :location, {}, "battery park") %>battery park <%= check_box("offering", :location, {}, "chelsea") %>chelsea <%= check_box("offering", :location, {}, "chinatown") %>chinatown
Comments
Post a Comment