Sri
Sri

Reputation: 39

radio button group for nested form in rails

How to create radio button in rails 3 when using nested form up to third level.

I have a group of radio buttons for listing . How can we achieve radio button with group name, attribute, value

f.fields_for :items do |item|
    item.fields_for :item_lists do |list|
        list.radio_button "radio_option_#{list.object.item_id}", :gender, 1  
    end
end
end

But this is not working as i had radio buttons based on Group name. thanks in advance.

Upvotes: 1

Views: 4235

Answers (1)

Kelly
Kelly

Reputation: 41501

Use form_for and fields_for:

= form_for @group do |f|
 - @group.users.each do |user|
  = f.fields_for user |u|
   = u.radio_button :gender

You can read more about usage here. I used HAML for the notation.

Upvotes: 2

Related Questions