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

hi there
I have this code
<%= collection_select ‘address’, ‘address’, @addresses, :id,
: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

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 :wink: 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
will certainly help you with if you want to do something like serialize
or some of the elements in a form to pass them back in a multi-level
independent of the actual form submission. It doesn’t sound like that’s
what you’re trying to do, though.


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’ )

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

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
and I must sign-off quickly or risk wife-ly reprecussions. Hope you
understand :slight_smile:

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

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

Hope to hear back.

Best regards,

Sorry. Just shows how very late it is here. I just looked at my
then the docs, and realized that collection_select doesn’t do what
trying to do. Use collection_select to generate the select box and
observe_field :with => ‘boo’ to get the selection to your controller

Be back in the AM.

Best regards,

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(
: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
but no luck
if theer is only one item in the collection it wont work