0

How can I handle different files selection ?

html.erb

in my form I have several fields and a select box :

<td><%= check_box_tag 'selected' , pfile.name %> </td>

browser

http:/myserver/files?x=true&selected=file1&selected=file2

I thought I then could do something like this in my

controller

if params[:x].present?
  #redirect to my download page with files[] for eg.
  # don't really know how to proceed..
else
  # return _error
end

Should I send my selected files(name) as an array ? Bad things may happen if too many files are selected and the URL is too large.. Although the size doesn't really matter , it that kind of situation I reckon it does though :)

BenMorel
  • 34,448
  • 50
  • 182
  • 322
user2567674
  • 171
  • 1
  • 3
  • 15
  • For the length of the request, this is interesting: http://stackoverflow.com/questions/1289585/what-is-apaches-maximum-url-length – Louis XIV Dec 12 '13 at 18:25

1 Answers1

0

You can just use the multiple option for your check_box_tag, post the form and retrieve the array from your controller.

Here's a good example

You might wanna do something like this :

<%=form_tag my_awesome_action_path do |f|%>
  <%@options.each do |option|%>
    <%=f.check_box_tag(:selected, {:multiple => true}, option, nil)%>
  <%end%>
  <%=f.submit_tag "Submit"%>
<%end%>
rb512
  • 6,880
  • 3
  • 36
  • 55
  • thanks for the link rb512 ! I'm concerned by the URL length though. Should I not be so ? – user2567674 Dec 12 '13 at 17:23
  • ok cool by the way I'm affraid the following code doesn't work : <%= pfile.check_box_tag(:selected, {:multiple => true}, option, nil) %> – user2567674 Dec 13 '13 at 11:53