radio_button_tag and default checked option

Hi, I can't get my radio button to be checked by default, here is what I have:

<%= f.radio_button :gender, "male", :checked => 'true' %><p>Male</p> <%= f.radio_button :gender, "female" %><p>Female</p>

Here is the generated html:

<input type="radio" value="true" name="user[gender]" id="user_gender_male"/>

Rails is going nuts here, why is Rails generating the id "user_gender_male"??? That's why everything is going wrong.

Karthi kn wrote:

I think, the way you are using the :checked option may be wrong.

Try with,

:checked => true :checked => 'checked'

Returns a radio button tag for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object). If the current value of method is tag_value the radio button will be checked. Additional options on the input tag can be passed as a hash with options. Examples

  # Let's say that @post.category returns "rails":   radio_button("post", "category", "rails")   # => <input type="radio" id="post_category" name="post[category]" value="rails" checked="checked" />

or just do :checked => 'checked' yourself in the options.