# Dynamically uploading a list that's already in a form

**URL:** <https://www.ruby-forum.com/t/dynamically-uploading-a-list-thats-already-in-a-form/86774>\
**Category:** Rails\
**Created:** [February 25, 2007, 8:07pm UTC](https://www.ruby-forum.com/t/dynamically-uploading-a-list-thats-already-in-a-form/86774 "2007-02-25T20:07:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![costi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@costi](https://www.ruby-forum.com/u/costi)\
**Post date:** [February 25, 2007, 8:07pm UTC](https://www.ruby-forum.com/t/dynamically-uploading-a-list-thats-already-in-a-form/86774/1 "2007-02-25T20:07:26Z")

</div>

I have the classic case of: Posts, and Categories. When the user submits  
a post, he has a drop-down list of categories. I want to put a “Add  
category” link next to the list of categories.

This is already inside a form, so a “link\_to\_remote” that creates a  
small AJAX form inside the “submit post” form will not work because that  
will mean to embed a form in another form.

I can popup a window that at the end refreshes the parent window or go  
to a page where the user can add categories and redirect at the submit  
post, but that seems so ten years ago.

Can anybody enlighten me on what’s the “best practice” way to update  
this categories list in a form? The web 2.0?

---

<div class="post-metadata">

**Author:** ![costi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@costi](https://www.ruby-forum.com/u/costi)\
**Post date:** [March 20, 2007, 5:34pm UTC](https://www.ruby-forum.com/t/dynamically-uploading-a-list-thats-already-in-a-form/86774/2 "2007-03-20T17:34:57Z")

</div>

Has anyone found a solid solution to this? This would be good for  
usability.

On Feb 25, 3:07 pm, Constantin G. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![costi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@costi](https://www.ruby-forum.com/u/costi)\
**Post date:** [March 20, 2007, 8:14pm UTC](https://www.ruby-forum.com/t/dynamically-uploading-a-list-thats-already-in-a-form/86774/3 "2007-03-20T20:14:23Z")

</div>

ebrad wrote:

> Has anyone found a solid solution to this? This would be good for  
> usability.

Since I didn’t got an answer, I’ve done it the way I thought best: I  
made a “false popup” with a div over the form. I used the Redbox plugin  
for that.

---

<div class="post-metadata">

**Author:** ![costi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@costi](https://www.ruby-forum.com/u/costi)\
**Post date:** [March 21, 2007, 6:29pm UTC](https://www.ruby-forum.com/t/dynamically-uploading-a-list-thats-already-in-a-form/86774/4 "2007-03-21T18:29:03Z")

</div>

Yes, that’s the way I wanted to do it too, but Redbox was putting the  
hidden popup div inside the main form, which I coudn’t get to work.  
Do you have an example that you could post?

Cheers

Brad W.

On Mar 20, 3:14 pm, Constantin G. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![costi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@costi](https://www.ruby-forum.com/u/costi)\
**Post date:** [March 30, 2007, 6:46am UTC](https://www.ruby-forum.com/t/dynamically-uploading-a-list-thats-already-in-a-form/86774/5 "2007-03-30T06:46:12Z")

</div>

ebrad wrote:

> Yes, that’s the way I wanted to do it too, but Redbox was putting the  
> hidden popup div inside the main form, which I coudn’t get to work.  
> Do you have an example that you could post?
> 
> Cheers
> 
> Brad W.

Put a div named however you want _outside your form_.  
In the form, use the :update =\> ‘div\_id’ parameter. I used the redbox  
convention of naming the div.

Copy/pasted from my code:  
\<%= link\_to\_remote\_redbox ‘Edit Container’, :update =\>  
‘hidden\_content\_edit\_container\_popup’,  
:url =\> {:action =\> ‘edit\_container\_popup’, :pin =\>  
container.pin } %\>

Then, you need to edit redbox\_helper.rb. You need to get rid of all that  
shit with “id” “hidden\_id”, and use your variable that you given in  
:update.  
You also need to tell redbox not to generate the div for you. So you are  
left with just two lines of code.

def link\_to\_remote\_redbox(name, link\_to\_remote\_options = {},  
html\_options = {})  
link\_to\_remote\_options =  
redbox\_remote\_options(link\_to\_remote\_options,  
link\_to\_remote\_options[:update])  
return link\_to\_remote(name, link\_to\_remote\_options, html\_options)  
end

Restart the server, and test. It works for me.

I have the dev website on a subdomain of [www.apluscompuservices.com](http://www.apluscompuservices.com) (btw

- dreamhost for rails is really slow). I’m not sure if my client like an  
“early launch” so if interested about the url, email me at  
removed\_email\_address@domain.invalid.

---

<div class="post-metadata">

**Author:** ![costi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@costi](https://www.ruby-forum.com/u/costi)\
**Post date:** [March 30, 2007, 8:10pm UTC](https://www.ruby-forum.com/t/dynamically-uploading-a-list-thats-already-in-a-form/86774/6 "2007-03-30T20:10:35Z")

</div>

In my app I simply have a submit\_to\_remote within the larger form…  
no need for a nested form. It submits the entire form including the  
other fields but I only read the category[:name] param when I receive  
it in my CategoriesController#create action.

Inside a larger form…  
\<%= text\_field\_tag ‘category[name]’ %\>  
\<%= submit\_to\_remote ‘add\_category’, ‘Add’, :url =\> categories\_path  
%\>

I belive there is a :submit parameter available for submit\_to\_remote  
that should specify which field(s) to submit instead of the whole  
form, but I haven’t played with that. (See the API doc for  
link\_to\_remote: as I understand it, submit\_to\_remote uses the same  
options.)

On Feb 25, 12:07 pm, Constantin G. \<rails-mailing-l…@andreas-
