# How to use :with =\>"this.value" in a collection select?

**URL:** <https://www.ruby-forum.com/t/how-to-use-with-this-value-in-a-collection-select/88380>\
**Category:** Rails\
**Created:** [March 10, 2007, 9:36am UTC](https://www.ruby-forum.com/t/how-to-use-with-this-value-in-a-collection-select/88380 "2007-03-10T09:36:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorge\_Mario\_GSMazo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71c47a/32.png) [@Jorge\_Mario\_GSMazo](https://www.ruby-forum.com/u/Jorge_Mario_GSMazo)\
**Post date:** [March 10, 2007, 9:36am UTC](https://www.ruby-forum.com/t/how-to-use-with-this-value-in-a-collection-select/88380/1 "2007-03-10T09:36:16Z")

</div>

hi there  
I have this code  
\<%= collection\_select ‘address’, ‘address’, @addresses, :id,  
:address,{},  
:onchange =\> remote\_function(:update =\> ‘shipping’, :url =\> { :action  
=\> :boota },  
:with =\> “‘boo’=this.value”) %\>

but in the controller

@boo = params[:boo] never gets the value  
can anyone help me with this  
google has been no help  
thanks in advance

---

<div class="post-metadata">

**Author:** ![Jorge\_Mario\_GSMazo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71c47a/32.png) [@Jorge\_Mario\_GSMazo](https://www.ruby-forum.com/u/Jorge_Mario_GSMazo)\
**Post date:** [March 10, 2007, 3:59pm UTC](https://www.ruby-forum.com/t/how-to-use-with-this-value-in-a-collection-select/88380/2 "2007-03-10T15:59:58Z")

</div>

Hi Jorge,

Jorge Mario G. Mazo wrote:

> \<%= collection\_select ‘address’, ‘address’, @addresses, :id, :address,{},  
> :with =\> “‘boo’=this.value”) %\>
> 
> but in the controller  
> @boo = params[:boo] never gets the value

The documentation on :with could definitely use some work, IMHO 😉 The  
good new is, all you need is

:with =\> ‘boo’

This puts the value in params[:boo]

Adding the ‘=’ after ‘boo’ tells Rails you’re going to get fancy, which  
it  
will certainly help you with if you want to do something like serialize  
all  
or some of the elements in a form to pass them back in a multi-level  
hash  
independent of the actual form submission. It doesn’t sound like that’s  
not  
what you’re trying to do, though.

hth,  
Bill

---

<div class="post-metadata">

**Author:** ![Jorge\_Mario\_GSMazo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71c47a/32.png) [@Jorge\_Mario\_GSMazo](https://www.ruby-forum.com/u/Jorge_Mario_GSMazo)\
**Post date:** [March 11, 2007, 7:32am UTC](https://www.ruby-forum.com/t/how-to-use-with-this-value-in-a-collection-select/88380/3 "2007-03-11T07:32:59Z")

</div>

hi there sir and sorry to bother but it doesnt work  
if I put some crazy in the :with I see an empty (–) debuging message

but if I use :with =\> ‘boo’ nothing happens

this is what I have in my \_form.rhtml

\<%= collection\_select ‘address’, ‘address’, @addresses, :id,  
:address,{}, :onchange =\> remote\_function(

```
                             :update => 'shipping',

                             :url => { :action => :boota },

                             :with => 'boo') %></p>

```

in the controller  
def boota  
@pp = params[:boo]  
render(:partial =\> ‘bo’ )  
end

and this is \_bo.rhtml  
\<%= debug(@pp) %\>

## I dont really know what am I doing wrong but I cant make it work thanks in advance

Jorge Mario G. Mazo

---

<div class="post-metadata">

**Author:** ![Jorge\_Mario\_GSMazo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71c47a/32.png) [@Jorge\_Mario\_GSMazo](https://www.ruby-forum.com/u/Jorge_Mario_GSMazo)\
**Post date:** [March 11, 2007, 9:38am UTC](https://www.ruby-forum.com/t/how-to-use-with-this-value-in-a-collection-select/88380/4 "2007-03-11T09:38:09Z")

</div>

Hi Jorge,

Jorge Mario G. Mazo wrote:

> ```
> :update => 'shipping',>
> :url => { :action => :boota },
> :with => 'boo') %></p>
> 
> ```

First, I’ll apologize in advance for my brief reply. It’s very late  
here  
and I must sign-off quickly or risk wife-ly reprecussions. Hope you  
understand 🙂

My recommendation / personal strategy in situations like this it simple.  
Make it simple. By that I mean, generate a sandbox app with just the  
bare  
minimum of stuff in it to get the behavior you’re looking for working.  
For  
starters, I’d get rid of the :onchange stuff.in the collection\_select  
and,  
once I got that working, put an observe\_field on it. Then, and only  
then,  
would I try to combine them.

Again, sorry I can’t be more help tonight. Time to retire.

Hope to hear back.

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![Jorge\_Mario\_GSMazo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71c47a/32.png) [@Jorge\_Mario\_GSMazo](https://www.ruby-forum.com/u/Jorge_Mario_GSMazo)\
**Post date:** [March 11, 2007, 9:53am UTC](https://www.ruby-forum.com/t/how-to-use-with-this-value-in-a-collection-select/88380/5 "2007-03-11T09:53:09Z")

</div>

Sorry. Just shows how very late it is here. I just looked at my  
response,  
then the docs, and realized that collection\_select doesn’t do what  
you’re  
trying to do. Use collection\_select to generate the select box and  
observe\_field :with =\> ‘boo’ to get the selection to your controller  
method.

Be back in the AM.

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![Jorge\_Mario\_GSMazo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71c47a/32.png) [@Jorge\_Mario\_GSMazo](https://www.ruby-forum.com/u/Jorge_Mario_GSMazo)\
**Post date:** [March 12, 2007, 6:47am UTC](https://www.ruby-forum.com/t/how-to-use-with-this-value-in-a-collection-select/88380/6 "2007-03-12T06:47:41Z")

</div>

thank you sir, it worked  
but now I have a new problem  
if the collection\_select only has 1 item the observe field will not work  
it works perfect with more than 1  
thanks for all your help!  
here is my new code:

\<%= collection\_select ‘address’, ‘address’, @addresses, :id, :address  
%\>

  
\<%= observe\_field(  
:address\_address,  
:update =\> ‘shipping’,  
:url =\> { :action =\> :shi },  
:complete =\> “new Effect.SlideDown(‘shipping’)”,  
:with =\> ‘boo’) %\>  
As I read that obseve\_fields take the same arguments of link\_to\_remote  
i have tried :on =\> click  
focus  
change  
but no luck  
if theer is only one item in the collection it wont work
