1

I have a set of checkboxes that I want to turn into a multiple selection input:

<div id="taxons_offered">
      <h3>Taxonomies Offered In</h3>
      <% for store in Store.all %>
               <% if store.has_taxonomies? %>
             <div store_id='<%= store.id %>'> 
                       <h4><%= store.name %></h4>
                      <ul class="multi-column-checkbox">
                              <% for taxonomy in store.taxonomies %>
                                      <li><%= check_box_tag "idea[taxonomy_ids][]",   
 taxonomy.id, @idea.taxonomies.include?(taxonomy) %> <%= taxonomy.name %></li>
                              <% end %>
                      </ul>
              </div>
       <% end %>
      <% end %>

I tried replacing check_box_tag with collection_select but it breaks

0

1 Answer 1

1

You have to describe how it's breaking? Is the Ruby not running or does the client side looks broken? If so where in the Ruby code is causing the error and how does the broken client side code look? Maybe even copy and paste the resulting clientside code?

I'll try to guess what you did wrong and make a response anyway.

First, you should always indent your code properly.

Second, your </div> should be placed out side the <% end %>

<div id="taxons_offered">
    <h3>Taxonomies Offered In</h3>
    <% for store in Store.all %>
        <% if store.has_taxonomies? %>
            <div store_id='<%= store.id %>'> 
            <h4><%= store.name %></h4>
            <ul class="multi-column-checkbox">
                <% for taxonomy in store.taxonomies %>
                    <li><%= check_box_tag "idea[taxonomy_ids][]",   
     taxonomy.id, @idea.taxonomies.include?(taxonomy) %> <%= taxonomy.name %></li>
                <% end %>
            </ul>
        <% end %>
    <% end %>
</div>

Try the code above and tell me if that makes any difference.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.