# Value of a list

**URL:** <https://www.ruby-forum.com/t/value-of-a-list/104198>\
**Category:** Rails\
**Created:** [May 15, 2007, 11:03am UTC](https://www.ruby-forum.com/t/value-of-a-list/104198 "2007-05-15T11:03:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 15, 2007, 11:03am UTC](https://www.ruby-forum.com/t/value-of-a-list/104198/1 "2007-05-15T11:03:33Z")

</div>

Hi all,

I am a newbie. Those are little technical questions that will look  
simple to me after a little while. But for the moment I am stuck.

I have a select list which I use to list the a marees table  
\<%= select ‘clim’, ‘maree\_id’, @marees.collect {|c| [c.nom, c.id]} %\>

I would like to create a link edit which would link to the edit page  
of the selected row of the list.

would you be so kind and give me an hint ?

Thanks

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 15, 2007, 11:46am UTC](https://www.ruby-forum.com/t/value-of-a-list/104198/2 "2007-05-15T11:46:49Z")

</div>

On May 15, 11:02 am, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> would you be so kind and give me an hint ?
> 
> Thanks

First, I’d use the method collection\_select, because then you don’t  
have to hassle with the collect call yourself.

As for your problem, you’re going to have to use javascript for that.  
You’ll have to change the edit link whenever the dropdown changes. As  
an HTML option, pass

:onchange =\> “update\_link(‘id\_of\_link’)”

and put a script in your view like:

You’ll have to find the nodes in link in which the relevant info is.  
I’m not too experienced with javascript, so I can’t help you there  
without trying it first.

It’s easier to just make a form, in which you select what you want to  
edit, and then press the edit button.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 15, 2007, 12:05pm UTC](https://www.ruby-forum.com/t/value-of-a-list/104198/3 "2007-05-15T12:05:46Z")

</div>

I am going to use collection\_select as you advise.

This list is alreay in a form : \_form.rhtml

2-Model \<%= select 'clim', 'themodel\_id', @themodels.collect {|c| [c.nom, c.id]} %\>

How would I do a form around that so poeple can edit what they have  
choosen ?

Thank you.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 15, 2007, 12:34pm UTC](https://www.ruby-forum.com/t/value-of-a-list/104198/4 "2007-05-15T12:34:09Z")

</div>

On May 15, 12:05 pm, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thank you.

First, as an exercise in Javascript, I decided to program it:

* * *

\<%= collection\_select(“clim”, “themodel\_id”, @themodels, “id”, “nom”,  
{}, {:onchange =\> “updateLink($(‘edit\_link’))”}) %\>

\<%= link\_to(‘edit’, {:action =\> “edit”, :id =\> “temp”}, {:id =\>  
“edit\_link”}) %\>

* * *

But, if you still want to use it, it up to you 🙂

About the form, that’s just a regular form as I’m sure you’ve made  
before.

\<%= form\_tag({:action =\> “edit”}) %\>

\<%= collection\_select(“clim”, “themodel\_id”, @themodels, “id”, “nom”)  
%\>

\<%= submit\_tag(“edit”) %\>  
\<%= end\_form\_tag %\>

Then in the edit action, params[“clim”][“themodel\_id”] is your id,  
which you can then use in whatever way you like.

BTW, in both situations, it may be cleaner not to use “select”, but  
“select\_tag”, because you’re only using the id to redirect you to  
somewhere else. “Select” takes in an object and method name, to be  
used for automatic attribute and retrieval for creating or editing  
values, but you don’t do that here.
