Link_To_Remote Incrementing

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:

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:

...

Any ideas as to go about doing this? In the mean time, I’m using actual
JavaScript…

Paul C. 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

Eric A. wrote:

Paul C. 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

The 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.

On 6/18/07, Paul C. [email protected] wrote:

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:

...

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

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

The array isn’t the problem at hand. My problem is making the have names that increment when you click the “add image”

so after I click once, the page will contain:

Two more clicks put this on the screen:

If you can help with this, I would love you forever.

Pavel Tzun wrote:

The array isn’t the problem at hand. My problem is making the 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:

<%=file_field_tag 'image[]'%> <%=link_to_function 'Add Another', "new Insertion.Bottom('upload', escape_javascript(file_field_tag 'image[]'))"%>

The above is not tested but something like that should work.

Eric

Eric A., 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.