Forum: Ruby on Rails how to use :with =>"this.value" in a collection select?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jorge Mario G. Mazo (Guest)
on 2007-03-10 10:36
(Received via mailing list)
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
Bill W. (Guest)
on 2007-03-10 16:59
(Received via mailing list)
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
Jorge Mario G. Mazo (Guest)
on 2007-03-11 08:32
(Received via mailing list)
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
Bill W. (Guest)
on 2007-03-11 10:38
(Received via mailing list)
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
Bill W. (Guest)
on 2007-03-11 10:53
(Received via mailing list)
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
Jorge Mario G. Mazo (Guest)
on 2007-03-12 07:47
(Received via mailing list)
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
%></p>
<%= 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
This topic is locked and can not be replied to.