Hey folks, I''m new to Ruby and Rails, so I''d like to ask you a quick question on how to make my program work as I need to. What I want to do is, have a link_to_remote called "Click Me!" which, upon clicking, will create an input field like the following: <input type="file" name="image0" /> That in itself is a piece of cake, but I''d also like to increment the number. For example, if the user wants to upload 300 images, they can click 300 times and the end result will be like: <input type="file" name="image0" /> <input type="file" name="image1" /> <input type="file" name="image2" /> <input type="file" name="image3" /> ... <input type="file" name="image299" /> Any ideas as to go about doing this? In the mean time, I''m using actual JavaScript... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Paul Chun wrote:> Any ideas as to go about doing this? In the mean time, I''m using actual > JavaScript...I would just stick to using actual JavaScript. No point in making the user wait for a request/response cycle. Eric --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Eric Anderson wrote:> Paul Chun wrote: >> Any ideas as to go about doing this? In the mean time, I''m using actual >> JavaScript... > > I would just stick to using actual JavaScript. No point in making the > user wait for a request/response cycle. > > EricThe problem here is if some guy clicked 200 times and after selecting the files he wanted, he decided he needed 201 files, then another click would reset the first 200 fields, leaving him with 201 empty fields. If there is no way of implementing this with Rails, then I can just cry to myself at night time. I just hope there is. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 6/18/07, Paul Chun <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hey folks, > > I''m new to Ruby and Rails, so I''d like to ask you a quick question on > how to make my program work as I need to. > > What I want to do is, have a link_to_remote called "Click Me!" which, > upon clicking, will create an input field like the following: > > <input type="file" name="image0" /> > > That in itself is a piece of cake, but I''d also like to increment the > number. For example, if the user wants to upload 300 images, they can > click 300 times and the end result will be like: > > <input type="file" name="image0" /> > <input type="file" name="image1" /> > <input type="file" name="image2" /> > <input type="file" name="image3" /> > ... > <input type="file" name="image299" />If you name all your inputs "image[]", you''ll get an array back in params. You might want to look at this as well: http://rubyonrailsnotes.blogspot.com/2007/03/multiple-file-uploads-with-attachmentfu.html --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> If you name all your inputs "image[]", you''ll get an array back in > params. > > You might want to look at this as well: > http://rubyonrailsnotes.blogspot.com/2007/03/multiple-file-uploads-with-attachmentfu.htmlThe array isn''t the problem at hand. My problem is making the <input type="file"> have names that increment when you click the "add image" so after I click once, the page will contain: <input type="file" name="image[0]" /> Two more clicks put this on the screen: <input type="file" name="image[0]" /> <input type="file" name="image[1]" /> <input type="file" name="image[2]" /> If you can help with this, I would love you forever. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Pavel Tzun wrote:> The array isn''t the problem at hand. My problem is making the <input > type="file"> have names that increment when you click the "add image"I''m not sure why you need to increment the number. Just name it "image[]" and it will be an array instead of a hash when the params receive it. Something like this should work: <div id="upload"> <%=file_field_tag ''image[]''%> <%=link_to_function ''Add Another'', "new Insertion.Bottom(''upload'', escape_javascript(file_field_tag ''image[]''))"%> </div> The above is not tested but something like that should work. Eric --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Eric Anderson, thank you so much! I finally got this hunk-o-junk working. I''m new to the RoR scene, so this whole Array thing makes my life 100.2 times easier. Like I promised, I love you forever. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---