samedi 21 février 2015

Rails checkboxes and jquery for a filtering form

I am trying to create a form filter that can narrow down my projects index page based on certain checkboxes that are selected in a jquery form that hides and shows. Here is what I have html wise:



<div id="project-filters" class="hidden-filters">
<p> Categories </p>
<% @categories.each do |category| %>
<%= check_box :category, category.name %> <%= category.name %><br/>
<% end %>
<br/>

<p> Location </p>
<% @locations.each do |location| %>
<%= check_box :location, location %> <%= location %> </br>
<% end %>
</br>

<p> Price Range </p>
<%= check_box :price, 0-100 %> <%= "0-100" %> </br>
<%= check_box :price, 100-500 %> <%= "100-500" %> </br>
<%= check_box :price, 500 %> <%= "500+" %> </br>

</div>


The problem is that I cannot figure out how to make checkboxes that exist outside of forms. Is this syntax even correct? I want the checkbox to have some data that corresponds to the name of the checkbox (the values in erb outside of the check_box helper) so that I can query the database once the checkbox is selected. But my html doesn't contain these values. I also just don't understand this api doc for check_box.


http://ift.tt/1q2E9Xi


What is the method here that the api docs are talking about?





Aucun commentaire:

Enregistrer un commentaire