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


#1

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


#2

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


#3

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


#4

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 :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
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


#5

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


#6

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