Observe_field and radio button... does not work?

I try to catch click on radio button, but nothing is executed…
Tested with RoR 1.1.2 and 1.1.3. What am I doing wrong?

<%= radio_button_tag(:city, ‘Dublin’) %>

<%= observe_field(:citi, :frequency => 0.5,
:on => ‘click’,
:with => “‘city=’ + $F(‘citi’)”,
:url => { :action => ‘remote_city_choosen’ })
%>

def remote_city_choosen
puts ‘#’ * 60 # nothing is displayed
p params[:citi] # on the console :frowning:
end


Jaroslaw Z.
http://blog.zabiello.com

Hi Jaroslaw,

Jaroslaw Z. wrote:

Just worked through some issues with this myself so…

<%= radio_button_tag(:city, ‘Dublin’) %>

<%= observe_field(:citi, :frequency => 0.5,

Two things here:

The first parameter to observe_field is the id of the field you’re
observing. In your case the line should start
<%= observe_field(‘city’ …
I’m not sure if a symbol will work. If it does, great. If not, go to a
quoted string in both the radio_button_tag and observe_field statements.

The default for radio_button is onchange so, unless you’ve some other
reason
for wanting to monitor it, you don’t need the :frequency setting.

                    :on => 'click',

Again, the default is for a radio_button is ‘onchange’. You don’t need
the
:on.

                    :with => "'city=' + $F('citi')",

The explanation in the documentation for the :with option is, IMHO,
entirely
incomprehensible. That’s probably because you can do more complicated
stuff
with it than most folks want/need to do. What :with does, in cases like
yours, is allow you to name the param in which the value in the field
you’re
observing will come back. So to get the value in the controller with
params[:city], all you need is :with => ‘city’.

hth,
Bill

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs