# Rails: radio button selection for nested forms objects

**URL:** <https://www.ruby-forum.com/t/rails-radio-button-selection-for-nested-forms-objects/174895>\
**Category:** Rails\
**Created:** [September 3, 2009, 5:05pm UTC](https://www.ruby-forum.com/t/rails-radio-button-selection-for-nested-forms-objects/174895 "2009-09-03T17:05:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![satynos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@satynos](https://www.ruby-forum.com/u/satynos)\
**Post date:** [September 3, 2009, 5:05pm UTC](https://www.ruby-forum.com/t/rails-radio-button-selection-for-nested-forms-objects/174895/1 "2009-09-03T17:05:34Z")

</div>

I have the following form for photo\_album which uses the nested forms  
feature of the Rails in saving the photos while updating the  
photo\_album. And having trouble with the selection of radio button  
value. I want only one of the photos be able to select as the album  
cover, but due to the way rails produces form element ids and names, I  
am able to select all of the photos as album covers. Is there any  
workaround?

\<% form\_for @photo\_album do |f| %\>  
\<%= f.error\_messages %\>

\<% @photo\_album.photos.each do |photo| %\>  
\<% f.fields\_for :photos, photo do |photo\_fields| %\>

\<%= image\_tag url\_for\_image\_column(photo, “data”, :thumb) %\>

  

\<%= photo\_fields.label :title %\>  
\<%= photo\_fields.text\_field :title %\>

  

\<%= photo\_fields.label :body %\>  
\<%= photo\_fields.text\_area :body %\>

  

\<%= photo\_fields.radio\_button :cover, “1” %\>  
\<%= photo\_fields.label :cover, ‘Album Cover’, :class =\> ‘option’  
%\>  
\<%= photo\_fields.check\_box :\_delete %\>  
\<%= photo\_fields.label :\_delete, ‘Delete’, :class =\> ‘option’ %\>

  
\<% end %\>  
\<% end %\> 

\<%= f.submit @photo\_album.new\_record? ? 'Create' : 'Update' %\>

\<% end %\>

And following is the html produced by rails (which is part of the  
problem) for radio buttons:

Album Cover Delete
