Forum: Ruby on Rails Observing Radio Buttons ??

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.
1344872832a8311b766bf2654782ab6f?d=identicon&s=25 Nitin (Guest)
on 2007-02-08 19:38
Observing Radio buttons

I am having some thing like the following code:
// Radio Button with id new_X
<input type="radio" name=" X" id="new_X" value= "new" /> <b> New X</b>
<br>

// Observe method on radio button
// test_X method exists in the controller and has a correspondin rhtml
file.
<% observe_field(:new_ X, :frequency => 0.1,
                     :update => :new_X _container,
                     :url => { :action => :test_X })
%>

// Container to change on clicking the radio button.
<div id = "new_ X_container">

</div>

Can you please help me as why this does not work ?

Thanks
Nitin.
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2007-02-08 20:42
(Received via mailing list)
Hi Nitin,

Nitin wrote:
>                     :url => { :action => :test_X })
> %>

Because you've hand-coded the field you're asking Rails to observe.
Rails
is server-side technology that generates the html and/or js to send to
the
browser.  But it only concerns itself with the stuff you tell it you
want it
to concern itself with.  You tell it that by using erb (embedded ruby)
in
your view files.  Any html you hand-code just gets passed straight
through
to the browser.  So in the case of your observe_field, Rails has no
knowledge of the form element you're asking it to generate js to
observe.
It'll get worse if you've hand-coded the form tags too.

If you're new to Rails, especially if you're coming from something like
PHP,
you'd really benefit from working through a tutorial or two to get the
hang
of how things work together.  At the risk of self-promotion, we just did
a
rewrite of Curt Hibb's "Rolling with Ruby on Rails" tutorial to bring it
up
to date with current (or at least near current) syntax / practices.
It's
at:

http://www.onlamp.com/pub/a/onlamp/2006/12/14/revi...

I hope you find it helpful.  And welcome to Rails!

Best regards,
Bill
This topic is locked and can not be replied to.