Rails multiple radio buttons not independent -


i new rails. part of form, want set of radio buttons each member.

as trial, part of /view is:

     <table>          <tr>             <% topic.listings.each |listing| %>                <td><%= listing %></td>             <% end %>           <tr>           <tr>              <% topic.listings.each |listing| %>                 <td>  <%= render 'layouts/button' %> </td>              <% end %>           </tr>      </table> 

layouts/_button.html.erb is:

    <%= radio_button_tag(:listing, "present") %>     <%= label_tag(:listing_present, "present") %><br>     <%= radio_button_tag(:listing, "absent") %>     <%= label_tag(:listing_absent, "absent") %><br>     <%= radio_button_tag(:listing, "unknown") %>     <%= label_tag(:listing_unknown, "unknown") %><br> 

and in /model:

   def self.listings       @listings = ["a","b","c"]    end 

this gives me set of 3 radio buttons under each member of listing desired radio button groups not independent. if button selected under "a" clicking button under "b" or "c" removes it.

please, how can groups of buttons independent. thank you.

howardg

this problem html generated. radio buttons grouped name.

the radio buttons geenerate have same name attribute (listing). that's why grouped together.

each group should have different name 3 buttonsand work.

 <% topic.listings.each |listing| %>    <td>  <%= render 'layouts/button', listing: listing %> </td>  <% end %> 

and

<%= radio_button_tag("listing_#{listing.id}", "present") %> <%= label_tag("listing_#{listing.id}_present", "present") %><br> <%= radio_button_tag("listing_#{listing.id}", "absent") %> <%= label_tag("listing_#{listing.id}_absent", "absent") %><br> <%= radio_button_tag("listing_#{listing.id}", "unknown") %> <%= label_tag("listing_#{listing.id}_unknown", "unknown") %><br> 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -