# Link\_To\_Remote Incrementing

**URL:** <https://www.ruby-forum.com/t/link-to-remote-incrementing/107192>\
**Category:** Rails\
**Created:** [June 19, 2007, 1:05am UTC](https://www.ruby-forum.com/t/link-to-remote-incrementing/107192 "2007-06-19T01:05:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sixofhearts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@sixofhearts](https://www.ruby-forum.com/u/sixofhearts)\
**Post date:** [June 19, 2007, 1:05am UTC](https://www.ruby-forum.com/t/link-to-remote-incrementing/107192/1 "2007-06-19T01:05:53Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![sixofhearts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@sixofhearts](https://www.ruby-forum.com/u/sixofhearts)\
**Post date:** [June 19, 2007, 1:26am UTC](https://www.ruby-forum.com/t/link-to-remote-incrementing/107192/2 "2007-06-19T01:26:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sixofhearts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@sixofhearts](https://www.ruby-forum.com/u/sixofhearts)\
**Post date:** [June 19, 2007, 10:02pm UTC](https://www.ruby-forum.com/t/link-to-remote-incrementing/107192/3 "2007-06-19T22:02:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sixofhearts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@sixofhearts](https://www.ruby-forum.com/u/sixofhearts)\
**Post date:** [June 19, 2007, 10:33pm UTC](https://www.ruby-forum.com/t/link-to-remote-incrementing/107192/4 "2007-06-19T22:33:53Z")

</div>

On 6/18/07, Paul C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://rubyonrailsnotes.blogspot.com/2007/03/multiple-file-uploads-with-attachmentfu.html)

---

<div class="post-metadata">

**Author:** ![sixofhearts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@sixofhearts](https://www.ruby-forum.com/u/sixofhearts)\
**Post date:** [June 20, 2007, 12:55am UTC](https://www.ruby-forum.com/t/link-to-remote-incrementing/107192/5 "2007-06-20T00:55:32Z")

</div>

> 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](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.

---

<div class="post-metadata">

**Author:** ![sixofhearts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@sixofhearts](https://www.ruby-forum.com/u/sixofhearts)\
**Post date:** [June 20, 2007, 1:28am UTC](https://www.ruby-forum.com/t/link-to-remote-incrementing/107192/6 "2007-06-20T01:28:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sixofhearts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@sixofhearts](https://www.ruby-forum.com/u/sixofhearts)\
**Post date:** [June 20, 2007, 1:53am UTC](https://www.ruby-forum.com/t/link-to-remote-incrementing/107192/7 "2007-06-20T01:53:01Z")

</div>

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.
