jeudi 19 novembre 2015

dynamicall create a table with checkboxes in rails as part of a form

I need to create a form where users can upload multiple files and then check off certain attributes before sending the files off. Each file input field should be displayed in a table, along with the checkboxes for each file input field.

However, I don't know ahead of time how many entries in the table there are. It depends on the number of files in a certain folder, and that changes.

So the code I have to create the table and form is:

<% counter = 0 %>
<%= simple_form_for(@myResource, :as => :myResource, :html => {:multipart => true}) do |f| %>
    <table>
        <% @filesInFolder.each do |file| %>
        <tr>
            <td>
                <%= // Need checkboxes here %>
            </td>
        </tr>
        <% counter = counter+1 %>
        <% end %>
    </table>
<% end %>

Now I can easily put the checkboxes and input fields using 'check_box_tag' and 'file_field_tag'. However, I am not sure how to access them on the other side, since I'm used to doing 'f.check_box' and 'f.file_field'. I don't know how to use 'f.check_box' in this case since I have to give them the names ahead of time

f.check_box :input_checkbox1 ...

And I need to give them dynamic names based on how many of these I create, so with 'check_box_tag' I can go

check_box_tag "checkBox#{counter}"

So how do I make checkboxes I can easily access with a controller for a form, but create as many as I need and name them dynamically?




Aucun commentaire:

Enregistrer un commentaire