Observe_field for radio_button

Hi,

I need to observe a set of radio buttons but am having great trouble. My
observe_field looks like this:

<%= observe_field :user_select, :frequency => 0, :url => { :action =>
:admin_control } %>

Now it works fine if I use a text_field like this:

<%= text_field :user, :select, “size” => 20, “maxlength” => 16 %>

But I want a radio button, and what I have is this:

<%= radio_button(“user”, “select”, user.id) %>

The above doesn’t work and neither does:

<%= radio_button_tag(“admin”, “select”, user.id) %>


I ahve no clue why the radio buttons don’t work with the observer. Any
help would be greatly appreciated!

Thanks,

Aditya

Aditya R. wrote:

<%= radio_button_tag(“admin”, “select”, user.id) %>
The current API docs have not been updated to reflect the fact that the
radio button helper creates an input with an id of object_method_value
rather than just object_method. (Remember: “View source” is your
friend.)

So you want:

<%= observe_field ‘user_select_’ + @user.id, … } %>

(You also want user to be an instance variable for the radio button
helper to create an appropriately-selected input.)


We develop, watch us RoR, in numbers too big to ignore.

Mark,

Thanks for the reply. Actually, I noticed in the page source that Rails
adds the @user.id part in the ‘id’ of the radio button. I tried your
solution soon after posting my earlier message, but surprisingly it
diidn’t work, although it created the same ‘id’ as the text_field does
:confused:

I think I’ve got it to wok by not using the radio_button method at all
but simply using the HTML tag like this:

<INPUT type=“radio” id=“user_select” name=“user[select]” value=<%=
user.id %> >

Your solution should work though, don’t know why it doesn’t.

-Aditya

Mark Reginald J. wrote:

Aditya R. wrote:

<%= radio_button_tag(“admin”, “select”, user.id) %>
The current API docs have not been updated to reflect the fact that the
radio button helper creates an input with an id of object_method_value
rather than just object_method. (Remember: “View source” is your
friend.)

So you want:

<%= observe_field ‘user_select_’ + @user.id, … } %>

(You also want user to be an instance variable for the radio button
helper to create an appropriately-selected input.)


We develop, watch us RoR, in numbers too big to ignore.

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